[wp-trac] [WordPress Trac] #24576: Make WP_Meta_Query accept arrays for keys

WordPress Trac noreply at wordpress.org
Fri Jun 14 02:56:58 UTC 2013


#24576: Make WP_Meta_Query accept arrays for keys
--------------------------+-----------------------------
 Reporter:  Viper007Bond  |      Owner:
     Type:  enhancement   |     Status:  new
 Priority:  lowest        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  3.5.1
 Severity:  trivial       |   Keywords:  needs-patch
--------------------------+-----------------------------
 #20312 touches on this but I thought of a much better solution for more
 complicated logic while still sticking to the API: allow the key to be an
 array which would inverse the overall relation value:

 For example, say you want this:

 `( key1 = abc OR key2 = abc ) AND key3 = def`

 You could simply do this:

 {{{
 'meta_query' => array(
         'relation' => 'AND',
         array(
                 'key' => array( 'key1', 'key2' ),
                 'value' => 'abc',
         ),
         array(
                 'key' => 'key3',
                 'value' => 'def',
         ),
 ),
 }}}

 Or for this:

 `( key1 = abc AND key2 = abc ) OR key3 = def`

 You'd just switch the `relation` to `OR`.

 Certainly edge case but I'm throwing it out there because I hate using
 filters to hack away at the SQL directly. :)

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


More information about the wp-trac mailing list