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

Prevent using the EP if query has unsuported orderby #3273

Merged
merged 10 commits into from
Feb 8, 2023
Merged

Conversation

burhandodhy
Copy link
Contributor

@burhandodhy burhandodhy commented Jan 25, 2023

Description of the Change

This PR prevents WordPress to use Elasticsearch if the Query does have unsupported orderby value

Closes #3272

How to test the Change

  1. Set the orderby => 'post__in' in WP_Query.
  2. Check the query should not use Elasticsearch.

Changelog Entry

Changed - Prevent using the Elasticsearch if query has unsupported orderby

Credits

Props @burhandodhy

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@burhandodhy burhandodhy added this to the 4.5.0 milestone Jan 25, 2023
Copy link
Member

@felipeelia felipeelia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@burhandodhy WP_Query's orderby also accepts an array and we need to account for that as well. Instead of checking

if ( in_array( $query->get( 'orderby' ), $unsupported_orderby, true ) ) {

we could do something like

if ( array_intersect( (array) $query->get( 'orderby' ), $unsupported_orderby ) ) {

Comment on lines 791 to 797
/**
* If WP_Query has unsupported orderby, skip ES query integration and use the WP query instead.
*
* @param bool $skip Whether to skip ES query integration
* @param \WP_Query $query WP_Query object
* @since 4.5
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@burhandodhy can we please document the function return as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent sending requests to ES if orderby is set to post__in
2 participants