[wp-trac] [WordPress Trac] #17011: Introduce 'relation' arg to meta_query

WordPress Trac wp-trac at lists.automattic.com
Mon Apr 18 13:16:30 UTC 2011


#17011: Introduce 'relation' arg to meta_query
-------------------------------------+------------------
 Reporter:  scribu                   |       Owner:
     Type:  enhancement              |      Status:  new
 Priority:  normal                   |   Milestone:  3.2
Component:  Query                    |     Version:
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |
-------------------------------------+------------------

Comment (by greuben):

 If `DISTINCT` isn't used the result includes same posts again and
 again(because of inner joins)

 '''Steps to reporduce:'''
 * Create a post with two meta keys 'foo' and 'bar'
 * Create a post with meta key 'foo'
 * Create a post with meta key 'bar'
 * Run this query
 {{{
 $q = new WP_Query(
 array(
         'fields' => 'ids',
         'ignore_sticky_posts' => true,
         'meta_query' => array(
                 'relation' => 'OR',
                 array(
                         'key' => 'foo',
                         'value' => array( 'foobar' ),
                         'compare' => 'IN'
                 ),
                 array(
                         'key' => 'bar',
                         'value' => array( 'foobar2' ),
                         'compare' => 'IN'
                 )
         )
 ) );
 print_r( $q->posts );
 }}}

 >Also, it's cleaner to set $relation this way:
 Agreed.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/17011#comment:5>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list