[wp-trac] [WordPress Trac] #46459: Inconsistent behaviour in WP_Query with single category__and and tag__and query vars

WordPress Trac noreply at wordpress.org
Sun Mar 10 11:05:28 UTC 2019


#46459: Inconsistent behaviour in WP_Query with single category__and and tag__and
query vars
--------------------------+-----------------------------
 Reporter:  seanleavey    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 In [https://github.com/WordPress/wordpress-
 develop/blob/f27fc64e2e3f6cbb3c85ac9b2200aaf4c37de3c8/src/wp-includes
 /class-wp-query.php#L1062 WP_Query::parse_tax_query], some code identifies
 if the submitted `category__and` query var contains only one entry, and if
 so, merges it into `category__in`:

 {{{#!php
 <?php
                 if ( ! empty( $q['category__and'] ) && 1 === count(
 (array) $q['category__and'] ) ) {
                         $q['category__and'] = (array) $q['category__and'];
                         if ( ! isset( $q['category__in'] ) ) {
                                 $q['category__in'] = array();
                         }
                         $q['category__in'][] = absint( reset(
 $q['category__and'] ) );
                         unset( $q['category__and'] );
                 }
 }}}

 This doesn't effect the returned results (a singular AND query can be
 interpreted as a single OR), but this behaviour is not consistently
 applied to singular tags in `tag__and`. Since `WP_Query` rewrites the
 contents of the query vars, though, this has ramifications for plugins
 that use the contents of these query vars.

 In my case, my plugin shows the contents of these query vars on the front
 end, and having items jump between query vars in the case of categories
 but not for tags may lead to confusion. I'm struggling to think why this
 behaviour is applied to categories but not tags, but I don't see why it
 can't be applied to both (or neither).

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


More information about the wp-trac mailing list