• Resolved congageorge

    (@congageorge)


    Hi.
    Im not getting any results when using post loop in search.php

    Pastebin: https://pastebin.com/jUj3aHX7

    When I remove the loop Relevanssi returns search result, but still lists 0 found from get_search_query().

    query_vars shows:
    array(71) { ["s"]=> string(8) "products" ["meta_query"]=> array(3) { [0]=> array(3) { ["key"]=> string(17) "_wp_page_template" ["value"]=> string(18) "page-thank_you.php" ["compare"]=> string(2) "!=" } [1]=> array(3) { ["key"]=> string(17) "_wp_page_template" ["value"]=> string(19) "page-template-2.php" ["compare"]=> string(2) "!=" } [2]=> array(3) { ["key"]=> string(17) "_wp_page_template" ["value"]=> string(19) "page-template-3.php" ["compare"]=> string(2) "!=" } } ["error"]=> string(0) "" ["m"]=> string(0) "" ["p"]=> int(0) ["post_parent"]=> string(0) "" ["subpost"]=> string(0) "" ["subpost_id"]=> string(0) "" ["attachment"]=> string(0) "" ["attachment_id"]=> int(0) ["name"]=> string(0) "" ["static"]=> string(0) "" ["pagename"]=> string(0) "" ["page_id"]=> int(0) ["second"]=> string(0) "" ["minute"]=> string(0) "" ["hour"]=> string(0) "" ["day"]=> int(0) ["monthnum"]=> int(0) ["year"]=> int(0) ["w"]=> int(0) ["category_name"]=> string(0) "" ["tag"]=> string(0) "" ["cat"]=> string(0) "" ["tag_id"]=> string(0) "" ["author"]=> string(0) "" ["author_name"]=> string(0) "" ["feed"]=> string(0) "" ["tb"]=> string(0) "" ["paged"]=> int(0) ["meta_key"]=> string(0) "" ["meta_value"]=> string(0) "" ["preview"]=> string(0) "" ["sentence"]=> string(0) "" ["title"]=> string(0) "" ["fields"]=> string(0) "" ["menu_order"]=> string(0) "" ["embed"]=> string(0) "" ["category__in"]=> array(0) { } ["category__not_in"]=> array(0) { } ["category__and"]=> array(0) { } ["post__in"]=> array(0) { } ["post__not_in"]=> array(0) { } ["post_name__in"]=> array(0) { } ["tag__in"]=> array(0) { } ["tag__not_in"]=> array(0) { } ["tag__and"]=> array(0) { } ["tag_slug__in"]=> array(0) { } ["tag_slug__and"]=> array(0) { } ["post_parent__in"]=> array(0) { } ["post_parent__not_in"]=> array(0) { } ["author__in"]=> array(0) { } ["author__not_in"]=> array(0) { } ["tax_query"]=> array(1) { [0]=> array(4) { ["taxonomy"]=> string(8) "language" ["field"]=> string(16) "term_taxonomy_id" ["terms"]=> int(127) ["operator"]=> string(2) "IN" } } ["ignore_sticky_posts"]=> bool(false) ["suppress_filters"]=> bool(false) ["cache_results"]=> bool(true) ["update_post_term_cache"]=> bool(true) ["lazy_load_term_meta"]=> bool(true) ["update_post_meta_cache"]=> bool(true) ["post_type"]=> string(3) "any" ["posts_per_page"]=> int(10) ["nopaging"]=> bool(false) ["comments_per_page"]=> string(2) "50" ["no_found_rows"]=> bool(false) ["search_terms_count"]=> int(1) ["search_terms"]=> array(1) { [0]=> string(8) "products" } ["search_orderby_title"]=> array(1) { [0]=> string(167) "wp_posts.post_title LIKE '{8f0e15daef86e6a7891cc9f1751d12fbf67afe964d2d2dc71d5034da843e721c}products{8f0e15daef86e6a7891cc9f1751d12fbf67afe964d2d2dc71d5034da843e721c}'" } ["taxonomy"]=> string(8) "language" ["term_id"]=> int(127) ["order"]=> string(4) "DESC" }

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Hmm, I only see the basic loop in that file, and that should definitely work with Relevanssi. Also, if you remove that loop, you should see no results whatsoever.

    Your query variables include a meta query that blocks posts from results based on their page template, and a language taxonomy filter. Those ok? Nothing special there, outside those two.

    Thread Starter congageorge

    (@congageorge)

    Hey Mikko.

    Thanks for taking a look!!
    Your input turned out to be very helpful. Looks like the code I was using to block searches on templates was the culprit. Results pilled in after disabling it.

    Thing is, I wanted a blanket method to stop “Thank you” pages from showing in search.
    Does Relevanssi have an option for this? Maybe in the Pro version?
    Or would mind you take a look at the code I’m using and offer a better suggestion?

    https://pastebin.com/padqGYRb

    Plugin Author Mikko Saari

    (@msaari)

    Premium has a simple checkbox for excluding posts from the index, but with the free version, you can do a filter that blocks those “Thank you” pages from being in the index in the first place. It’s the best approach: instead of blocking them in every search, you block them once on indexing.

    The filter hook is relevanssi_do_not_index. Something like this:

    add_filter( 'relevanssi_do_not_index', 'rlv_template_block', 10, 2 );
    function rlv_template_block( $block, $post_id ) {
        $template = get_post_meta( $post_id, '_wp_page_template', true );
        if ( 'page-thank_you.php' === $template ) {
            $block = true;
        }
        return $block;
    }

    Add that and rebuild the index, that should get rid of those pages.

    Thread Starter congageorge

    (@congageorge)

    Thanks again Mikko!!
    Used the above suggested hook and it works like a charm.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘No Results when inside loop’ is closed to new replies.