Skip to main contentSkip to footer

If you use PostX Pro to build a search results template using their Post Grid block, you’ll notice that the search results don’t work with Relevanssi enabled. If Relevanssi is active, you get no search results, and if Relevanssi is deactivated, results show up.

This problem happens because PostX Pro uses WP_Query to fetch the results, and Relevanssi by default blocks the default WP_Query searches – most of the time, they’re useless, as Relevanssi will override the results anyway. In this case, that override does not happen, so you’re left without any results at all.

Fortunately, the fix is simple. Add this function to your site:

add_action(
  'pre_get_posts',
  function( $query ) {
    if ( $query->is_search() && isset( $query->query_vars['s'] ) ) {
      $query->set( 'relevanssi', true );
    }
  }
);

This function is attached to all queries with the pre_get_posts hook. If the query is a search query (the search term parameter s is set), this function also sets the relevanssi flag to true. Setting this flag will make Relevanssi take over the search. Now the Post Grid will show Relevanssi-generated results.

If you want to see the Relevanssi-generated excerpts with highlights in the Post Grid, make sure you adjust the Post Grid settings and enable the “Show Full Excerpt” setting under Excerpt. This adjustment will make the Post Grid use the excerpt Relevanssi generates.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

GDPR Compliance

We have a privacy policy that covers your use of this web site and our customer data use. However, if you’re interested in how using Relevanssi affects the GDPR compliance of your own site, here we have answers for you. In general, Relevanssi doesn’t store any information about users and…

Related searches feature
John Blackbourn wrote a cool related searches feature for Relevanssi Premium. It’s included from version 1.7.4. In order to use…
Brizy Pro
Brizy is another WordPress site builder and as usual, it too has hard-coded queries that don’t play nice with Relevanssi.…

Related Posts:

Comment Section:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed