[wp-trac] [WordPress Trac] #29031: Wp Query tax_query multiple query individual OR query

WordPress Trac noreply at wordpress.org
Sat Jul 26 03:29:43 UTC 2014


#29031: Wp Query tax_query multiple query individual OR query
--------------------------+-----------------------------
 Reporter:  dunar21       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  3.9.1
 Severity:  normal        |   Keywords:
  Focuses:  performance   |
--------------------------+-----------------------------
 Considering this:


 {{{
 $args = array(
         'post_type' => 'post',
         'tax_query' => array(
                 'relation' => 'AND',
                 array(
                         'taxonomy' => 'movie_genre',
                         'field' => 'slug',
                         'terms' => array('action')
                 ),
                 array(
                         'taxonomy' => 'actors',
                         'field' => 'id',
                         'terms' => array(25, 26),
                         'operator' => 'IN'
                 )
         )
 );
 $query = new WP_Query( $args );
 }}}

 I would expect the result set to include all posts that are assigned a
 'movie_genre' taxonomy of 'action' AND all of those movies, of that genre,
 who have actors (tax) with id's of 25 and 26.

 This is the expected result, however, if actor 25 has no posts associated
 with his tax term id and actor 26 does, the result set will return empty.

 If the terms are switched :

 {{{
 $args = array(
         'post_type' => 'post',
         'tax_query' => array(
                 'relation' => 'AND',
                 array(
                         'taxonomy' => 'movie_genre',
                         'field' => 'slug',
                         'terms' => array('action')
                 ),
                 array(
                         'taxonomy' => 'actors',
                         'field' => 'id',
                         'terms' => array(26, 25),/*!!!!! CHANGE HERE
 !!!!*/
                         'operator' => 'IN'
                 )
         )
 );
 $query = new WP_Query( $args );
 }}}

 Then the result set turns out as expected.  All posts of genre action with
 actor 26 are displayed (because actor 25 has no posts).  So, because the
 first in the terms array for the second tax_query has results, it queries
 correctly.  If reversed, because the first in the terms array for the
 second tax_query has no results, it queries incorrectly.

 I believe this behavior is a bug.  The "IN" operator should return a
 result set similar to "OR" despite the order of placement of term ids for
 the second tax_query.

 I have not tested if the same occurs for the first query, or for one
 individual tax_query. However, the expected action of this type of query
 would be :

 "Give me all POSTS which have a GENRE of ACTION '''''and''''' include any
 of the ACTORS in this ARRAY(IDS).

--
Ticket URL: <https://core.trac.wordpress.org/ticket/29031>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list