Category and tag are typically checked before checking for a custom taxonomy. If the global query matches category or tag (even if it also has tax_query set), return category/tag as the queried object, instead of arbitrarily returning the first term in the `tax_query` stack (typically those added with 'pre_get_posts').

Real world example: http://www.emusic.com/17dots/topics/daily-download/ - "tag" page, regionalized for US-only content using `pre_get_posts` passing in the terms "US" and "ALL" for "region" (custom tax). All of the theme functions would output "ALL" as the term name. Even though it was a tag archive, the queried object was an arbitrary term from `tax_query`.

See [26006]. All unit tests pass.
Fixes #20767.



Built from https://develop.svn.wordpress.org/trunk@26007


git-svn-id: http://core.svn.wordpress.org/trunk@25938 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2013-11-04 23:54:10 +00:00
parent a5eb3208d7
commit ca85591c3c
1 changed files with 13 additions and 8 deletions

View File

@ -3248,20 +3248,25 @@ class WP_Query {
$this->queried_object_id = 0;
if ( $this->is_category || $this->is_tag || $this->is_tax ) {
if ( $this->is_category ) {
$term = get_term( $this->get( 'cat' ), 'category' );
} elseif ( $this->is_tag ) {
$term = get_term( $this->get( 'tag_id' ), '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 );
if ( 'term_id' == $query['field'] )
$term = get_term( reset( $query['terms'] ), $query['taxonomy'] );
elseif ( $query['terms'] )
else
$term = get_term_by( $query['field'], reset( $query['terms'] ), $query['taxonomy'] );
}
if ( ! empty( $term ) && ! is_wp_error( $term ) ) {
$this->queried_object = $term;
$this->queried_object_id = (int) $term->term_id;
if ( $this->is_category )
if ( $this->is_category && 'category' === $this->queried_object->taxonomy )
_make_cat_compat( $this->queried_object );
}
} elseif ( $this->is_post_type_archive ) {