-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Network wide search may switch away from the site the search is performed on #2121
Comments
Hi @gonzomir, By default, ElasticPress won't search on other sites unless the FWIW, I've tried adding it with the following snippet and things seem to work as expected:
|
Hi, @felipeelia, In my case the |
Thanks @gonzomir, I can reproduce it now. It seems the root cause of it is a call to Do you want to craft a Pull Request with that and we can run some tests with it? Thanks in advance! |
Yes, I will, no problem. |
Closing this one as #2283 was merged. Thanks! |
Describe the bug
When retrieving the posts in a network-wide search, a
switch_to_blog()
is called as part ofthe_post
hook, butrestore_current_blog()
is not called immediately after that, it's called in the nextthe_post
hook if the next post is from a different site. This works OK in the loop, but some plugins (Yoast for example) may trigger the hook outside the loop. In that case WordPress will be left switched to the blog the first result came from, and if it's not the blog the search was performed on, unexpected thing happen.I didn't go that deep to investigate what exactly Yoast is doing, but the hook is triggered when it generates it's output in the
<head />
.Steps to Reproduce
I'm sorry, but I can't share a public URL where the bug can be observed.
Expected behavior
The expected behaviour would be the site name not to change because of the returned results.
Environment information
Additional context
My workaround was the following:
Maybe at the end of
QueryIntegration::maybe_switch_to_blog()
a similar check should be made:The text was updated successfully, but these errors were encountered: