Posted on

Gutenberg Full Site Editing

There’s something of a compatibility issue between Relevanssi and Gutenberg Full Site Editing. No results are found when you create a Query Loop to display the search results with Relevanssi enabled. The blank results happen because the post template block doesn’t use the Relevanssi results but instead uses a new WP_Query. Since Relevanssi still blocks the default search, this comes up empty.

For a straightforward solution, add this to your site:

add_filter( 'relevanssi_search_ok', function( $ok, $query ) {
  if ( ! empty( $query->query_vars['s'] ) ) {
    $ok = true;
  }
  return $ok;
}, 10, 2 );

This function hooks to the relevanssi_search_ok filter hook. This hook fires because Relevanssi looks at the newly-created WP_Query, but since it’s not the main query for the template, Relevanssi doesn’t take over. This function instructs Relevanssi to take over as long as there’s a s parameter in the query and a search term exists.

2 comments Gutenberg Full Site Editing

  1. Thank you for the clarification!

    Quick question: Is this problem something that should be fixed in Twenty Twenty-Two itself or is this underlying issue only applicable to Relevanssi and is it something caused by the plugin that you plan to fix in future releases?

    I am asking because, if this is coming from the theme, we should open an issue in trac at https://core.trac.wordpress.org/ (I am more than happy to open it myself, I just want to make sure I understand the details first).

    Thanks again, your plugin rocks!

    1. The underlying issue is the way the Query Loop block in Gutenberg works, so this applies to all themes with full site editing, not just Twenty Twenty-Two. I don’t think opening a ticket will help; it’s quite likely this needs to be done this way in the Query Loop. Relevanssi will likely automatically use this filter function for sites that use full site editing in the future, so this should not be a major problem.

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.