diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index d8089e8d00..2ad5959364 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -549,7 +549,8 @@ function wp_title($sep = '»', $display = true, $seplocation = '') { // If there's a taxonomy if ( is_tax() ) { - $tax = get_taxonomy( get_query_var('taxonomy') ); + $term = get_queried_object(); + $tax = get_taxonomy( $term->taxonomy ); $title = single_term_title( $tax->labels->name . $t_sep, false ); } diff --git a/wp-includes/query.php b/wp-includes/query.php index 9e09addc78..81601aac98 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -1943,13 +1943,30 @@ class WP_Query { $where .= get_tax_sql( $q['tax_query'], "$wpdb->posts.ID" ); // Back-compat - $cat_query = wp_list_filter( $q['tax_query'], array( 'taxonomy' => 'category', 'operator' => 'IN' ) ); - if ( !empty( $cat_query ) ) { - $cat_query = reset( $cat_query ); - $cat = get_term_by( $cat_query['field'], $cat_query['terms'][0], 'category' ); - if ( $cat ) { - $this->set( 'cat', $cat->term_id ); - $this->set( 'category_name', $cat->slug ); + $tax_query_in = wp_list_filter( $q['tax_query'], array( 'operator' => 'IN' ) ); + if ( !empty( $tax_query_in ) ) { + if ( !isset( $q['taxonomy'] ) ) { + foreach ( $tax_query_in as $a_tax_query ) { + if ( !in_array( $a_tax_query['taxonomy'], array( 'category', 'post_tag' ) ) ) { + $q['taxonomy'] = $a_tax_query['taxonomy']; + if ( 'slug' == $a_tax_query['field'] ) + $q['term'] = $a_tax_query['terms'][0]; + else + $q['term_id'] = $a_tax_query['terms'][0]; + + break; + } + } + } + + $cat_query = wp_list_filter( $tax_query_in, array( 'taxonomy' => 'category' ) ); + if ( !empty( $cat_query ) ) { + $cat_query = reset( $cat_query ); + $cat = get_term_by( $cat_query['field'], $cat_query['terms'][0], 'category' ); + if ( $cat ) { + $this->set( 'cat', $cat->term_id ); + $this->set( 'category_name', $cat->slug ); + } } } }