From 50dc04d43bff25b92991b08261097856e008bdc0 Mon Sep 17 00:00:00 2001 From: scribu Date: Sat, 9 Oct 2010 10:19:15 +0000 Subject: [PATCH] Get rid of redundant ->tax_query. See #12891 git-svn-id: http://svn.automattic.com/wordpress/trunk@15765 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/canonical.php | 2 +- wp-includes/classes.php | 37 +++++++++++++------------------------ wp-includes/query.php | 29 +++++++++++++++++++---------- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index 65df0edf5..81af9be62 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -146,7 +146,7 @@ function redirect_canonical($requested_url=null, $do_redirect=true) { } elseif ( is_category() || is_tag() || is_tax() ) { // Terms (Tags/categories) $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'] ); $obj = $wp_query->get_queried_object(); diff --git a/wp-includes/classes.php b/wp-includes/classes.php index fb8e415d8..0baf3005e 100644 --- a/wp-includes/classes.php +++ b/wp-includes/classes.php @@ -563,27 +563,6 @@ class WP_Object_Query { */ 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 * @@ -694,16 +673,26 @@ class WP_Object_Query { * @access protected * @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 * @return string */ - function get_tax_sql( $object_id_column ) { + function get_tax_sql( $tax_query, $object_id_column ) { global $wpdb; $sql = array(); - foreach ( $this->tax_query as $query ) { + foreach ( $tax_query as $query ) { if ( !isset( $query['include_children'] ) ) $query['include_children'] = true; diff --git a/wp-includes/query.php b/wp-includes/query.php index 98d996211..c66cb3097 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -1081,7 +1081,6 @@ class WP_Query extends WP_Object_Query { unset($this->posts); unset($this->query); $this->query_vars = array(); - $this->tax_query = array(); $this->meta_query = array(); unset($this->queried_object); unset($this->queried_object_id); @@ -1399,7 +1398,15 @@ class WP_Query extends WP_Object_Query { 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'] ) ) { $tax_query = $q['tax_query']; } 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'] ) { switch ( $query['taxonomy'] ) { case 'category': @@ -1845,7 +1852,7 @@ class WP_Query extends WP_Object_Query { $search = apply_filters_ref_array('posts_search', array( $search, &$this ) ); // Taxonomies - if ( !empty( $this->tax_query ) ) { + if ( !empty( $q['tax_query'] ) ) { if ( empty($post_type) ) { $post_type = 'any'; $post_status_join = true; @@ -1853,11 +1860,11 @@ class WP_Query extends WP_Object_Query { $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 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 ) ) { $cat_query = reset( $cat_query ); $cat = get_term_by( $cat_query['field'], $cat_query['terms'][0], 'category' ); @@ -2514,9 +2521,11 @@ class WP_Query extends WP_Object_Query { $this->queried_object = NULL; $this->queried_object_id = 0; - if ( $this->tax_query ) { - $query = reset( $this->tax_query ); - if ( 'term_id' == $query['field'] ) + $tax_query = $this->get('tax_query'); + + if ( !empty( $tax_query ) ) { + $query = reset( $tax_query ); + if ( 'term_id' == $query['field'] ) $term = get_term( reset( $query['terms'] ), $query['taxonomy'] ); else $term = get_term_by( $query['field'], reset( $query['terms'] ), $query['taxonomy'] );