[wp-trac] [WordPress Trac] #36343: Taxonomy query matching specified term or NOT EXISTS does not return expected result

WordPress Trac noreply at wordpress.org
Sat Mar 26 04:52:44 UTC 2016


#36343: Taxonomy query matching specified term or NOT EXISTS does not return
expected result
--------------------------+-----------------------------
 Reporter:  crstauf       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  4.4.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Performing a query on a (custom) taxonomy looking for a specified term or
 no term specified (NOT EXISTS) does not return the expected results. I
 discovered when working on a custom post type, but I tested on the post
 type, and the bug persisted.

 Steps to reproduce:
 1. Register a custom taxonomy
 2. Create two posts, one assigned a term within the custom taxonomy, the
 other not
 3. Perform query on the posts, with the following `tax_query` array:
 {{{
 #!php
 $args['tax_query'] = array(
         'relation' => 'OR',
         array(
                 'taxonomy' => 'custom_tax',
                 'field' => 'slug',
                 'terms' => 'the_term',
         ),
         array(
                 'taxonomy' => 'custom_tax',
                 'operator' => 'NOT EXISTS',
         ),
 );
 }}}

 (If you want to get really funky, create another post with a post format;
 in my discovery moment it was 'audio,' but I suspect it wouldn't matter
 which format.)

 This query selects posts that have the specified term, but not posts that
 do not have any term assigned (within `custom_tax`). If you created a post
 with a format, that post will be included in the results as well.

 See also:
 [https://core.trac.wordpress.org/ticket/29181 Ticket #29181]
 [https://core.trac.wordpress.org/changeset/29896 Changeset 29896 (fixes
 #29181)]

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


More information about the wp-trac mailing list