[wp-trac] [WordPress Trac] #42164: Conditional Tags not working when using ugly URL

WordPress Trac noreply at wordpress.org
Tue Oct 10 13:15:48 UTC 2017


#42164: Conditional Tags not working when using ugly URL
---------------------------+------------------------------
 Reporter:  petersplugins  |       Owner:
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Query          |     Version:  4.8.2
 Severity:  normal         |  Resolution:
 Keywords:                 |     Focuses:  template
---------------------------+------------------------------

Comment (by jdgrimes):

 It looks like this is because in `parse_query()`, `is_category` is only
 set if the `$tax_query` has an `'operator'` specified:

 {{{#!php
 <?php
                         $this->parse_tax_query( $qv );

                         foreach ( $this->tax_query->queries as $tax_query
 ) {
                                 if ( ! is_array( $tax_query ) ) {
                                         continue;
                                 }

                                 if ( isset( $tax_query['operator'] ) &&
 'NOT IN' != $tax_query['operator'] ) {
                                         switch ( $tax_query['taxonomy'] )
 {
                                                 case 'category':
                                                         $this->is_category
 = true;
                                                         break;
                                                 case 'post_tag':
                                                         $this->is_tag =
 true;
                                                         break;
                                                 default:
                                                         $this->is_tax =
 true;
                                         }
                                 }
                         }
 }}}

 And in `parse_tax_query()`, the `'cat'` query arg doesn't end up using an
 operator:

 {{{#!php
 <?php
                 // Category stuff
                 if ( ! empty( $q['cat'] ) && ! $this->is_singular ) {
                         $cat_in = $cat_not_in = array();

                         // snip

                         foreach ( $cat_array as $cat ) {
                                 if ( $cat > 0 )
                                         $cat_in[] = $cat;
                                 elseif ( $cat < 0 )
                                         $cat_not_in[] = abs( $cat );
                         }

                         if ( ! empty( $cat_in ) ) {
                                 $tax_query[] = array(
                                         'taxonomy' => 'category',
                                         'terms' => $cat_in,
                                         'field' => 'term_id',
                                         'include_children' => true
                                 );
                         }

                         // snip
                 }

 }}}

 I don't know if this is expected behavior or not. Looking at the history
 of the `isset( $tax_query['operator'] )` condition might tell the tale.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42164#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list