Re-introduce ->tax_query as a read-only var. See #12891

git-svn-id: http://svn.automattic.com/wordpress/trunk@16414 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
scribu 2010-11-17 02:04:08 +00:00
parent f58b21e69d
commit 275888f2e6
2 changed files with 16 additions and 9 deletions

View File

@ -146,7 +146,7 @@ function redirect_canonical($requested_url=null, $do_redirect=true) {
} elseif ( is_category() || is_tag() || is_tax() ) { // Terms (Tags/categories) } elseif ( is_category() || is_tag() || is_tax() ) { // Terms (Tags/categories)
$term_count = 0; $term_count = 0;
foreach ( $wp_query->get('tax_query') as $tax_query ) foreach ( $wp_query->tax_query as $tax_query )
$term_count += count( $tax_query['terms'] ); $term_count += count( $tax_query['terms'] );
$obj = $wp_query->get_queried_object(); $obj = $wp_query->get_queried_object();

View File

@ -708,6 +708,15 @@ class WP_Query {
*/ */
var $query_vars = array(); var $query_vars = array();
/**
* Taxonomy query, as passed to get_tax_sql()
*
* @since 3.1.0
* @access public
* @var array
*/
var $tax_query = array();
/** /**
* Holds the data for a single object that is queried. * Holds the data for a single object that is queried.
* *
@ -1931,9 +1940,9 @@ 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
$q['tax_query'] = $this->parse_tax_query( $q ); $this->tax_query = $this->parse_tax_query( $q );
if ( !empty( $q['tax_query'] ) ) { if ( !empty( $this->tax_query ) ) {
$clauses = call_user_func_array( 'get_tax_sql', array( $q['tax_query'], $wpdb->posts, 'ID', &$this) ); $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'];
@ -1946,7 +1955,7 @@ class WP_Query {
} }
// Back-compat // Back-compat
$tax_query_in = wp_list_filter( $q['tax_query'], array( 'operator' => 'IN' ) ); $tax_query_in = wp_list_filter( $this->tax_query, array( 'operator' => 'IN' ) );
if ( !empty( $tax_query_in ) ) { if ( !empty( $tax_query_in ) ) {
if ( !isset( $q['taxonomy'] ) ) { if ( !isset( $q['taxonomy'] ) ) {
foreach ( $tax_query_in as $a_tax_query ) { foreach ( $tax_query_in as $a_tax_query ) {
@ -2646,10 +2655,8 @@ class WP_Query {
$this->queried_object = NULL; $this->queried_object = NULL;
$this->queried_object_id = 0; $this->queried_object_id = 0;
$tax_query = $this->get('tax_query'); if ( !empty( $this->tax_query ) ) {
$query = reset( $this->tax_query );
if ( !empty( $tax_query ) ) {
$query = reset( $tax_query );
if ( 'term_id' == $query['field'] ) if ( 'term_id' == $query['field'] )
$term = get_term( reset( $query['terms'] ), $query['taxonomy'] ); $term = get_term( reset( $query['terms'] ), $query['taxonomy'] );