Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#29285 closed defect (bug) (fixed)

meta_query fails with multiple clauses that have non-default 'compare' values

Reported by: boonebgorges's profile boonebgorges Owned by: nacin's profile nacin
Milestone: 4.0 Priority: normal
Severity: normal Version:
Component: Query Keywords:
Focuses: Cc:

Description

It appears that when using 'meta_query' with multiple clauses, where those clauses have an explicit value set for 'compare', will cause the query to fail. This is true even when the 'compare' operator is '='. For example:

'meta_query' => array(
    'relation' => 'AND',
    array(
        'key' => 'foo',
        'value' => 'bar',
        'compare' => '=',
    ),
    array(
        'key' => 'foo2',
        'value' => 'bar2',
        'compare' => '=',
    ),
),

This will return no values, while removing the 'compare' params will make it work. This appears to be the case for all values of compare.

I'm attaching a number of unit tests that demonstrate this problem for a couple different values of 'relation' and 'compare'.

I haven't dug deep into the root cause, but at a glance, it appears that the SQL clauses are not being clustered into parentheses correctly - it's getting short-circuited by the 'compare' logic.

Attachments (2)

29285.unit-test.patch (4.1 KB) - added by boonebgorges 10 years ago.
29285.unit-test.2.patch (4.1 KB) - added by boonebgorges 10 years ago.
fixes @ticket :)

Download all attachments as: .zip

Change History (5)

@boonebgorges
10 years ago

fixes @ticket :)

#1 @boonebgorges
10 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

On further investigation, this problem is caused by r28659 #25538. I'm going to close this ticket and continue discussion on that ticket.

#2 @nacin
10 years ago

  • Owner set to nacin
  • Resolution changed from duplicate to fixed

In 29650:

Meta Query: Revert [28659] (and [28665]) due to regressions.

props boonebgorges.
fixes #29285. see #25538.

#3 @nacin
10 years ago

  • Milestone changed from Awaiting Review to 4.0
Note: See TracTickets for help on using tickets.