Skip to content

BUG: FSE template-parts replaced in Multisite searches #4352

Description

@dannyreaktiv

Describe the bug

The Good: I’ve gotten the cross-site searching working with ElasticSearch on a WP Multisite that’s running an FSE theme.

The Bug: sometimes, when $query->set( 'site__in', 'all' ); is on, the Header FSE template-part gets replaced with the post_content from another site’s post with the same ID. The Header template-part’s post_id is 510, but the content that is rendered on the front-end is from the 510 of another site on the network.

The fix was to add $query->set( 'cache_results', false );, as shown below.

Is this expected behavior?

function elasticsearch_network_search( $query ) {
 … if ( is_admin() || ! $query->is_main_query() || ! $query->is_search() ) { return; }
$query->set( 'site__in', 'all' );
$query->set( 'cache_results', false ); 

}
 add_action( 'pre_get_posts', 'elasticsearch_network_search');

Steps to Reproduce

On a multisite setup, have a search result include the post ID of a FSE template part used on the page

Screenshots, screen recording, code snippet

No response

Environment information

No response

WordPress and ElasticPress information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions