Make WordPress Core


Ignore:
Timestamp:
12/22/2013 06:30:09 PM (10 years ago)
Author:
wonderboymusic
Message:

Fix a regression for get_queried_object() by checking for category_name when cat isn't set - mainly is_category() being true for Uncategorized or when queried object is accessed in pre_get_posts. Also check for $query['terms'] when trying to assign a term as the queried object when is_tax() is true. Adds a unit test. See [26007] for how I originally broke this while fixing a bigger issue.

Props Chouby, jeremyfelt.
Fixes #26634, #26627.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/query.php

    r26525 r26864  
    32653265        if ( $this->is_category || $this->is_tag || $this->is_tax ) {
    32663266            if ( $this->is_category ) {
    3267                 $term = get_term( $this->get( 'cat' ), 'category' );
     3267                if ( $this->get( 'cat' ) ) {
     3268                    $term = get_term( $this->get( 'cat' ), 'category' );
     3269                } elseif ( $this->get( 'category_name' ) ) {
     3270                    $term = get_term_by( 'slug', $this->get( 'category_name' ), 'category' );
     3271                }
    32683272            } elseif ( $this->is_tag ) {
    32693273                $term = get_term( $this->get( 'tag_id' ), 'post_tag' );
    3270             } else {
     3274            } elseif ( $query['terms'] ) {
    32713275                $tax_query_in_and = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'NOT IN' ), 'NOT' );
    32723276                $query = reset( $tax_query_in_and );
Note: See TracChangeset for help on using the changeset viewer.