Don't do any taxonomy stuff if is_singular. See #15487

git-svn-id: https://develop.svn.wordpress.org/trunk@16515 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
scribu 2010-11-20 21:51:21 +00:00
parent 3484e62eca
commit 6401205f36
1 changed files with 48 additions and 48 deletions

View File

@ -1593,19 +1593,17 @@ class WP_Query {
); );
} }
if ( !$this->is_singular() ) { foreach ( $tax_query as $query ) {
foreach ( $tax_query as $query ) { if ( 'IN' == $query['operator'] ) {
if ( 'IN' == $query['operator'] ) { switch ( $query['taxonomy'] ) {
switch ( $query['taxonomy'] ) { case 'category':
case 'category': $this->is_category = true;
$this->is_category = true; break;
break; case 'post_tag':
case 'post_tag': $this->is_tag = true;
$this->is_tag = true; break;
break; default:
default: $this->is_tax = true;
$this->is_tax = true;
}
} }
} }
} }
@ -1945,46 +1943,48 @@ class WP_Query {
$search = apply_filters_ref_array('posts_search', array( $search, &$this ) ); $search = apply_filters_ref_array('posts_search', array( $search, &$this ) );
// Taxonomies // Taxonomies
$this->tax_query = $this->parse_tax_query( $q ); if ( !$this->is_singular ) {
if ( !empty( $this->tax_query ) ) { $this->tax_query = $this->parse_tax_query( $q );
$clauses = call_user_func_array( 'get_tax_sql', array( $this->tax_query, $wpdb->posts, 'ID', &$this) ); if ( !empty( $this->tax_query ) ) {
$clauses = call_user_func_array( 'get_tax_sql', array( $this->tax_query, $wpdb->posts, 'ID', &$this) );
$join .= $clauses['join']; $join .= $clauses['join'];
$where .= $clauses['where']; $where .= $clauses['where'];
if ( $this->is_tax ) { if ( $this->is_tax ) {
if ( empty($post_type) ) { if ( empty($post_type) ) {
$post_type = 'any'; $post_type = 'any';
$post_status_join = true; $post_status_join = true;
} elseif ( in_array('attachment', (array) $post_type) ) { } elseif ( in_array('attachment', (array) $post_type) ) {
$post_status_join = true; $post_status_join = true;
}
}
// Back-compat
$tax_query_in = wp_list_filter( $this->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' ) ); // Back-compat
if ( !empty( $cat_query ) ) { $tax_query_in = wp_list_filter( $this->tax_query, array( 'operator' => 'IN' ) );
$cat_query = reset( $cat_query ); if ( !empty( $tax_query_in ) ) {
$cat = get_term_by( $cat_query['field'], $cat_query['terms'][0], 'category' ); if ( !isset( $q['taxonomy'] ) ) {
if ( $cat ) { foreach ( $tax_query_in as $a_tax_query ) {
$this->set( 'cat', $cat->term_id ); if ( !in_array( $a_tax_query['taxonomy'], array( 'category', 'post_tag' ) ) ) {
$this->set( 'category_name', $cat->slug ); $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 );
}
} }
} }
} }