Get rid of redundant ->tax_query. See #12891

git-svn-id: http://svn.automattic.com/wordpress/trunk@15765 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
scribu 2010-10-09 10:19:15 +00:00
parent c3a31b6576
commit 50dc04d43b
3 changed files with 33 additions and 35 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->tax_query as $tax_query ) foreach ( $wp_query->get('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

@ -563,27 +563,6 @@ class WP_Object_Query {
*/ */
var $meta_query = array(); var $meta_query = array();
/*
* List of taxonomy queries
*
* A query is an associative array:
* - 'taxonomy' string|array The taxonomy being queried
* - 'terms' string|array The list of terms
* - 'field' string (optional) Which term field is being used.
* Possible values: 'term_id', 'slug' or 'name'
* Default: 'slug'
* - 'operator' string (optional)
* Possible values: 'IN' and 'NOT IN'.
* Default: 'IN'
* - 'include_children' bool (optional) Whether to include child terms.
* Default: true
*
* @since 3.1.0
* @access public
* @var array
*/
var $tax_query = array();
/* /*
* Populates the $meta_query property * Populates the $meta_query property
* *
@ -694,16 +673,26 @@ class WP_Object_Query {
* @access protected * @access protected
* @since 3.1.0 * @since 3.1.0
* *
* @uses $this->tax_query * @param array $tax_query List of taxonomy queries. A single taxonomy query is an associative array:
* - 'taxonomy' string|array The taxonomy being queried
* - 'terms' string|array The list of terms
* - 'field' string (optional) Which term field is being used.
* Possible values: 'term_id', 'slug' or 'name'
* Default: 'slug'
* - 'operator' string (optional)
* Possible values: 'IN' and 'NOT IN'.
* Default: 'IN'
* - 'include_children' bool (optional) Whether to include child terms.
* Default: true
* *
* @param string $object_id_column * @param string $object_id_column
* @return string * @return string
*/ */
function get_tax_sql( $object_id_column ) { function get_tax_sql( $tax_query, $object_id_column ) {
global $wpdb; global $wpdb;
$sql = array(); $sql = array();
foreach ( $this->tax_query as $query ) { foreach ( $tax_query as $query ) {
if ( !isset( $query['include_children'] ) ) if ( !isset( $query['include_children'] ) )
$query['include_children'] = true; $query['include_children'] = true;

View File

@ -1081,7 +1081,6 @@ class WP_Query extends WP_Object_Query {
unset($this->posts); unset($this->posts);
unset($this->query); unset($this->query);
$this->query_vars = array(); $this->query_vars = array();
$this->tax_query = array();
$this->meta_query = array(); $this->meta_query = array();
unset($this->queried_object); unset($this->queried_object);
unset($this->queried_object_id); unset($this->queried_object_id);
@ -1399,7 +1398,15 @@ class WP_Query extends WP_Object_Query {
do_action_ref_array('parse_query', array(&$this)); do_action_ref_array('parse_query', array(&$this));
} }
function parse_tax_query( $q ) { /*
* Populates the 'tax_query' property
*
* @access protected
* @since 3.1.0
*
* @param array &$q The query variables
*/
function parse_tax_query( &$q ) {
if ( ! empty( $q['tax_query'] ) && is_array( $q['tax_query'] ) ) { if ( ! empty( $q['tax_query'] ) && is_array( $q['tax_query'] ) ) {
$tax_query = $q['tax_query']; $tax_query = $q['tax_query'];
} else { } else {
@ -1502,9 +1509,9 @@ class WP_Query extends WP_Object_Query {
); );
} }
$this->tax_query = $tax_query; $q['tax_query'] = $tax_query;
foreach ( $this->tax_query as $query ) { foreach ( $q['tax_query'] as $query ) {
if ( 'IN' == $query['operator'] ) { if ( 'IN' == $query['operator'] ) {
switch ( $query['taxonomy'] ) { switch ( $query['taxonomy'] ) {
case 'category': case 'category':
@ -1845,7 +1852,7 @@ class WP_Query extends WP_Object_Query {
$search = apply_filters_ref_array('posts_search', array( $search, &$this ) ); $search = apply_filters_ref_array('posts_search', array( $search, &$this ) );
// Taxonomies // Taxonomies
if ( !empty( $this->tax_query ) ) { if ( !empty( $q['tax_query'] ) ) {
if ( empty($post_type) ) { if ( empty($post_type) ) {
$post_type = 'any'; $post_type = 'any';
$post_status_join = true; $post_status_join = true;
@ -1853,11 +1860,11 @@ class WP_Query extends WP_Object_Query {
$post_status_join = true; $post_status_join = true;
} }
$where .= $this->get_tax_sql( "$wpdb->posts.ID" ); $where .= $this->get_tax_sql( $q['tax_query'], "$wpdb->posts.ID" );
// Back-compat // Back-compat
if ( !empty( $ids ) ) { if ( !empty( $ids ) ) {
$cat_query = wp_list_filter( $this->tax_query, array( 'taxonomy' => 'category' ) ); $cat_query = wp_list_filter( $q['tax_query'], array( 'taxonomy' => 'category' ) );
if ( !empty( $cat_query ) ) { if ( !empty( $cat_query ) ) {
$cat_query = reset( $cat_query ); $cat_query = reset( $cat_query );
$cat = get_term_by( $cat_query['field'], $cat_query['terms'][0], 'category' ); $cat = get_term_by( $cat_query['field'], $cat_query['terms'][0], 'category' );
@ -2514,8 +2521,10 @@ class WP_Query extends WP_Object_Query {
$this->queried_object = NULL; $this->queried_object = NULL;
$this->queried_object_id = 0; $this->queried_object_id = 0;
if ( $this->tax_query ) { $tax_query = $this->get('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'] );
else else