[wp-trac] [WordPress Trac] #30681: Using a value in a meta_query (in WP_Query) combined with EXISTS OR NOT EXISTS breaks query

WordPress Trac noreply at wordpress.org
Fri Dec 12 00:59:59 UTC 2014


#30681: Using a value in a meta_query (in WP_Query) combined with EXISTS OR NOT
EXISTS breaks query
--------------------------+--------------------
 Reporter:  barrykooij    |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  4.1
Component:  Query         |     Version:  trunk
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:
--------------------------+--------------------
Changes (by boonebgorges):

 * keywords:  needs-unit-tests has-patch 2nd-opinion => has-patch


Comment:

 barrykooij, thanks for the report.

 Your interpretation of NOT EXISTS is correct. In 4.0, a 'value' passed
 with 'NOT EXISTS' would be ignored. [attachment:30681.diff] fixes this for
 4.1.

 EXISTS is different. Prior to 4.1, there was a quirk in the way that
 EXISTS was parsed. See
 https://core.trac.wordpress.org/browser/tags/4.0.1/src/wp-
 includes/meta.php#L1028 - 'EXISTS' is not a whitelisted value for
 'compare', so becomes '='. If no value was passed, the result was a SQL
 query along the lines of `WHERE meta_key = 'foo'`, which is semantically
 the same as an EXISTS query. But passing a 'value' would make a SQL clause
 like `WHERE meta_key = 'foo' AND meta_value = 'bar'`. The tests and the
 fix in [attachment:30681.diff] reflect this behavior in < 4.1. (IMO this
 is sort of a bug, but I'm concern at this point with preserving existing
 behavior.)

 I've verified these additional tests as passing on 4.0.1, failing on the
 current 4.1 branch, and fixed by the additional cases in
 [attachment:30681.diff].

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30681#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list