From db1badfcaba07d36cfb86ab52baa7b2cc1380282 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Wed, 12 Mar 2014 04:08:18 +0000 Subject: [PATCH] In `WP_Query::get_queried_object()`, account for `pre_get_posts` by checking for `tag` when `tag_id` isn't present. Tags still need to be rolled up into `tax_query`. Add a unit test confirming expected query vars during and after `pre_get_posts`. Props mattonomics for a patch. See #27362. Built from https://develop.svn.wordpress.org/trunk@27511 git-svn-id: http://core.svn.wordpress.org/trunk@27354 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/query.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index 0f7e104f99..25436d96fb 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -3663,7 +3663,11 @@ class WP_Query { $term = get_term_by( 'slug', $this->get( 'category_name' ), 'category' ); } } elseif ( $this->is_tag ) { - $term = get_term( $this->get( 'tag_id' ), 'post_tag' ); + if ( $this->get( 'tag_id' ) ) { + $term = get_term( $this->get( 'tag_id' ), 'post_tag' ); + } elseif ( $this->get( 'tag' ) ) { + $term = get_term_by( 'slug', $this->get( 'tag' ), 'post_tag' ); + } } else { $tax_query_in_and = wp_list_filter( $this->tax_query->queries, array( 'operator' => 'NOT IN' ), 'NOT' ); $query = reset( $tax_query_in_and );