[wp-trac] [WordPress Trac] #17235: meta_query fails if you don't pass in an array of arrays

WordPress Trac wp-trac at lists.automattic.com
Mon Apr 25 20:20:40 UTC 2011


#17235: meta_query fails if you don't pass in an array of arrays
--------------------------+-----------------------------
 Reporter:  batmoo        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  3.1
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 This tripped me up the first time I used meta_query (see #16563) and I've
 seen others fall into the same trap. If you don't pass in an array of
 arrays into meta_query, it generates some funky (but valid) SQL and fails
 to return anything.

 The main instance where people will fall into this is if they only have a
 single key/value pair to look for. In this case, passing in an array of
 arrays does not seem intuitive, and meta_query should be smart enough to
 work with either. Examples below.

 This doesn't work:

 {{{
 $my_query = WP_Query( array
         array (
                 'post_type' => 'post',
                 'meta_query' => array (
                         'key' => 'my_key',
                         'value' => 'my_value',
                 ),
         ),
 );
 }}}

 But this does:

 {{{
 $my_query = WP_Query( array
         array (
                 'post_type' => 'post',
                 'meta_query' => array (
                         array(
                                 'key' => 'my_key',
                                 'value' => 'my_value',
                         }
                 ),
         ),
 );
 }}}

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


More information about the wp-trac mailing list