[wp-trac] [WordPress Trac] #20604: Empty tax_query returns all posts

WordPress Trac wp-trac at lists.automattic.com
Thu Aug 30 05:03:28 UTC 2012


#20604: Empty tax_query returns all posts
--------------------------+------------------------------
 Reporter:  Ninos Ego     |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Query         |     Version:  3.3.1
 Severity:  minor         |  Resolution:
 Keywords:  has-patch     |
--------------------------+------------------------------
Changes (by wonderboymusic):

 * keywords:  needs-patch => has-patch


Comment:

 Yep - the problem is the OR relation, the script bails the loop early and
 doesn't tell the wear clause that the tax_query is garbage. To test:

 {{{

 $q = new WP_Query( array(
         'fields'        => 'ids',
         'tax_query' => array(
                 'relation' => 'OR',
                 array(
                         'taxonomy' => 'post_tag',
                         'field' => 'id',
                         'terms' => false,
                         'operator' => 'IN'
                 ),
                 array(
                         'taxonomy' => 'category',
                         'field' => 'id',
                         'terms' => false,
                         'operator' => 'IN'
                 )
         )

 ) );

 print_r( $q->posts );
 exit();
 }}}

 Should return an empty array - does so with my patch, attached.

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


More information about the wp-trac mailing list