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

Meta queries after first meta query stripped from nested meta queries #1812

Closed
christianc1 opened this issue Jun 20, 2020 · 2 comments · Fixed by #2567
Closed

Meta queries after first meta query stripped from nested meta queries #1812

christianc1 opened this issue Jun 20, 2020 · 2 comments · Fixed by #2567
Assignees
Milestone

Comments

@christianc1
Copy link
Member

Describe the bug
When you are nesting meta queries more than a single level deep, all but the first meta query is stripped out of the deeper queries.

Take for example:

$meta_query = array(
    array(
        array(
            'key' => 'key1',
            'value' => 'on',
        ),
        array(
            'key' => 'key2'
            'value' => 'off'
        ),
        'relation' => 'AND'
    ),
    array(
        'key' => 'key3',
        'value' => 'red',
    ),
    'relation' => 'OR',
);

In this example, the meta query on key2 get's stripped out because of https://github.com/10up/ElasticPress/blob/develop/includes/classes/Indexable.php#L488

Steps to Reproduce

  1. Nest multiple meta queries at a depth of 2.
  2. Inspect EP request
  3. meta_query[0][1] is missing.

Expected behavior
Meta queries should not disappear.

Screenshots

Environment information

  • Device: Macbook Pro
  • OS: MacOS 10.14.6
  • WordPress version: 5.4.2
  • EP Version: 3.4.1
@christianc1
Copy link
Member Author

Note, you can workaround this issue by ensuring that relation key is the first element in the array, but that's sort of luck. Happy to submit a patch, but the code causing this issue looks like it's in there to handle another strange edge case. Maybe we can discuss the original intent more @tlovett1.

@Jamiewarb
Copy link

Jamiewarb commented May 7, 2021

Thank you @christianc1 this comment has saved me from more days of pulling my hair out trying to understand what's going wrong.

Would love to see this fixed if possible, or potentially documented as a known bug in the docs

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

Successfully merging a pull request may close this issue.

5 participants