Posted on

PostX Pro

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:

  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.

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

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