From 014007f029aa0960aa97747773136b6c82d5ccf9 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sun, 22 Dec 2013 18:31:12 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@26864 git-svn-id: http://core.svn.wordpress.org/trunk@26750 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/query.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index 1ec9566c41..d64a25a709 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -3264,10 +3264,14 @@ class WP_Query { if ( $this->is_category || $this->is_tag || $this->is_tax ) { if ( $this->is_category ) { - $term = get_term( $this->get( 'cat' ), 'category' ); + if ( $this->get( 'cat' ) ) { + $term = get_term( $this->get( 'cat' ), 'category' ); + } elseif ( $this->get( 'category_name' ) ) { + $term = get_term_by( 'slug', $this->get( 'category_name' ), 'category' ); + } } elseif ( $this->is_tag ) { $term = get_term( $this->get( 'tag_id' ), 'post_tag' ); - } else { + } elseif ( $query['terms'] ) { $tax_query_in_and = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'NOT IN' ), 'NOT' ); $query = reset( $tax_query_in_and );