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

Exclude category taxonomy from root tax check #2299

Closed
wants to merge 19 commits into from

Conversation

oscarssanchez
Copy link
Contributor

Description of the Change

Fixes #2242

As WordPress core sets the category_name parameter when performing a Tax Query if you are doing an id's search, this conflicts with this check EP does here: https://github.com/10up/ElasticPress/blob/develop/includes/classes/Indexable/Post/Post.php#L1003

This problem only applies to the category taxonomy.

Alternate Designs

Benefits

Possible Drawbacks

Verification Process

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

Changelog Entry

@oscarssanchez oscarssanchez requested a review from Rahmon August 16, 2021 22:44
@Rahmon Rahmon self-assigned this Aug 17, 2021
@Rahmon
Copy link
Contributor

Rahmon commented Aug 17, 2021

@oscarssanchez looks good.

Do you mind in add a test if the key terms.category.slug and terms.category.term_id are not present when we use the same args used in #2242 ?

Something similar to https://github.com/10up/ElasticPress/blob/develop/tests/php/indexables/TestUser.php#L712

@Rahmon Rahmon assigned oscarssanchez and unassigned Rahmon Aug 17, 2021
* @group post
*/
public function testCatIdTaxQuery() {
$term = Functions\create_and_sync_term( 'test', 'Test category', 'The testing category', 'category' );
Copy link
Contributor

Choose a reason for hiding this comment

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

the PHPUnit is getting an error in this line Error: Call to a member function index() on bool

);

$this->assertContains( $term, $args['post_filter']['bool']['must'][0]['bool']['must'][0]['terms']['terms.category.term_id'] );
$this->assertNotContains( 'test', $args['post_filter']['bool']['must'][0]['bool']['must'][1]['terms']['terms.category.slug'] );
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to update the assertion because ['must'][1]['terms']['terms.category.slug'] doesn't exist and I think it'll always return true.

Maybe we need to check if the array $args['post_filter']['bool']['must'][0]['bool']['must'] has only one item (assertCount) and if this only item $args['post_filter']['bool']['must'][0]['bool']['must'][0]['terms'] has the key terms.category.term_id (assertArrayHasKey).

Makes sense?

@felipeelia felipeelia added this to the 3.6.2 milestone Aug 19, 2021
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.

BUG: Wrong results while filtering by category using 'tax_query'
3 participants