[wp-trac] [WordPress Trac] #22967: Null value in meta query changes the type of comparison

WordPress Trac noreply at wordpress.org
Mon Dec 17 00:05:35 UTC 2012


#22967: Null value in meta query changes the type of comparison
-----------------------------+--------------------------
 Reporter:  bradyvercher     |       Type:  defect (bug)
   Status:  new              |   Priority:  normal
Milestone:  Awaiting Review  |  Component:  Query
  Version:  trunk            |   Severity:  normal
 Keywords:  has-patch        |
-----------------------------+--------------------------
 If a null value is set in a meta query, it effectively returns the same
 results as setting the 'compare' arg to 'EXISTS', even if it's explicitly
 set to the default '='.

 For example:

 {{{
 $value_var = null;
 ...
 meta_query => array(
         array(
             'key'     => '_my_meta_key',
             'value'   => $value_var,
             'compare' => '='
         )
     )
 ...
 }}}

 That returns all rows where '_my_meta_key' exists and ignores 'value'
 instead of treating it like an empty string. This can be troublesome where
 the value is passed in dynamically like the example, so validation would
 have to be done prior to every meta query to ensure the value isn't null.

 I've attached a patch for review that checks for the existence of the
 'value' key rather than using `isset` and casts it to a string if it's
 null.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22967>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list