From 939d6de74860ef1304bda3fbbf62e634aa04f13f Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 9 Jan 2011 20:49:11 +0000 Subject: [PATCH] Don't parse cat query var twice. Don't include children for category__* queries. Props SergeyBiryukov. see #16152 git-svn-id: http://svn.automattic.com/wordpress/trunk@17246 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/query.php | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index 6ce4e5bc1..5a2d6fe28 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -1230,6 +1230,15 @@ class WP_Query { */ var $is_post_type_archive = false; + /** + * Whether the tax query has been parsed once. + * + * @since 3.1.0 + * @access private + * @var bool + */ + var $parsed_tax_query = false; + /** * Resets query flags to false. * @@ -1485,6 +1494,7 @@ class WP_Query { $this->is_date = true; } + $this->parsed_tax_query = false; $this->parse_tax_query( $qv ); foreach ( $this->tax_query->queries as $tax_query ) { @@ -1671,7 +1681,7 @@ class WP_Query { } // Category stuff - if ( !empty($q['cat']) && '0' != $q['cat'] && !$this->is_singular ) { + if ( !empty($q['cat']) && '0' != $q['cat'] && !$this->is_singular && !$this->parsed_tax_query ) { $q['cat'] = ''.urldecode($q['cat']).''; $q['cat'] = addslashes_gpc($q['cat']); $cat_array = preg_split('/[,\s]+/', $q['cat']); @@ -1684,8 +1694,10 @@ class WP_Query { $cat = abs($cat); if ( $in ) { $q['category__in'][] = $cat; + $q['category__in'] = array_merge( $q['category__in'], get_term_children($cat, 'category') ); } else { $q['category__not_in'][] = $cat; + $q['category__not_in'] = array_merge( $q['category__not_in'], get_term_children($cat, 'category') ); } } $q['cat'] = implode(',', $req_cats); @@ -1696,7 +1708,8 @@ class WP_Query { $tax_query[] = array( 'taxonomy' => 'category', 'terms' => $q['category__in'], - 'field' => 'term_id' + 'field' => 'term_id', + 'include_children' => false ); } @@ -1705,7 +1718,8 @@ class WP_Query { $tax_query[] = array( 'taxonomy' => 'category', 'terms' => $q['category__not_in'], - 'operator' => 'NOT IN' + 'operator' => 'NOT IN', + 'include_children' => false ); } @@ -1715,7 +1729,8 @@ class WP_Query { 'taxonomy' => 'category', 'terms' => $q['category__and'], 'field' => 'term_id', - 'operator' => 'AND' + 'operator' => 'AND', + 'include_children' => false ); } @@ -1773,6 +1788,8 @@ class WP_Query { ); } + $this->parsed_tax_query = true; + $this->tax_query = new WP_Tax_Query( $tax_query ); }