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

WPML: Replacing posts with translations

…); // Replace with our new filter. function relevanssi_wpml_filter_show_translation( $data ) { $wpml_post_type_setting = apply_filters( ‘wpml_setting’, false, ‘custom_posts_sync_option’ ); $current_blog_language = get_bloginfo( ‘language’ ); $filtered_hits = array(); foreach ( $data[0] as $hit ) { $original_hit = $hit; $object_array = relevanssi_get_an_object( $hit ); $hit = $object_array[‘object’]; $format = $object_array[‘format’]; if (……( function_exists( ‘icl_object_id’ ) && ! function_exists( ‘pll_is_translated_post_type’ ) ) { if ( $sitepress->is_translated_post_type( $hit->post_type ) ) { $fallback_to_default = false; if ( isset( $wpml_post_type_setting[ $hit->post_type ] ) && ‘2’ === $wpml_post_type_setting[ $hit->post_type ] ) { $fallback_to_default = true; } $id = apply_filters( ‘wpml_object_id’, $hit->ID, $hit->post_type, $fallback_to_default ); // This……is a post in a translated post type. if ( intval( $hit->ID ) === intval( $id ) ) { // The post is in the current language. if ( ! in_array( $id, wp_list_pluck( $filtered_hits, ‘ID’ ), false ) ) { $filtered_hits[] = $original_hit; } } elseif ( intval( $hit->ID )…

Gutenberg Full Site Editing
There’s a compatibility issue between Relevanssi and Gutenberg Full Site Editing. No results are found when you create a Query…
Indexing attachment file names
Relevanssi has been working nicely for the normal usecase. But how does one setup indexing of attachment files. When someone…

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