Skip to content
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

Restore current blog when the_post triggers outside the loop. #2283

Merged
merged 4 commits into from
Aug 2, 2021

Conversation

felipeelia
Copy link
Member

This Pull Request is a "take over" of #2144.

Description of the Change

As described in #2121, in multisite environment and searching the whole network when the_post is triggered outside the loop, the current site is not restored if the first result is from another blog. To fix the issue I'm checking if the WP_Query instance is in the loop and if not, calling restore_current_blog(). To do this properly I had to add second argument to ElasticPress\Indexable\Post\QueryIntegration->maybe_switch_to_blog().

Alternate Designs

In the project where I first discovered the issue I added another function to the_post to restore the current blog, but that is not necessary if the issue can be addressed at it's roots.

Benefits

Fix the issue, described in #2121. The original PR content:

Possible Drawbacks

I can't find any.

Verification Process

I tested that the issue dissappears in my test setup and made sure current tests are passing.

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Applicable Issues

Issue #2121.

Changelog Entry

Fix: Restore current blog when the_post triggers outside the loop in multisite environment and the whole network is searched if the first result is from another blog. Props @gonzomir

@felipeelia felipeelia added this to the 3.6.2 milestone Aug 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants