From 21af801a5acdf8dcb2b58f16d7ed5c0b1f0d44b9 Mon Sep 17 00:00:00 2001 From: scribu Date: Wed, 20 Oct 2010 12:07:23 +0000 Subject: [PATCH] Fix 'taxonomy' and 'term' query var logic. See #12891 git-svn-id: http://svn.automattic.com/wordpress/trunk@15860 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/classes.php | 7 ++---- wp-includes/query.php | 49 +++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 29 deletions(-) diff --git a/wp-includes/classes.php b/wp-includes/classes.php index 5cbcd8878..2a4c3d63e 100644 --- a/wp-includes/classes.php +++ b/wp-includes/classes.php @@ -281,10 +281,7 @@ class WP { } } - if ( isset( $taxonomy_query_vars[$wpvar] ) ) { - $this->query_vars['taxonomy'] = $taxonomy_query_vars[$wpvar]; - $this->query_vars['term'] = $this->query_vars[$wpvar]; - } elseif ( isset($post_type_query_vars[$wpvar] ) ) { + if ( isset($post_type_query_vars[$wpvar] ) ) { $this->query_vars['post_type'] = $post_type_query_vars[$wpvar]; $this->query_vars['name'] = $this->query_vars[$wpvar]; } @@ -1904,4 +1901,4 @@ class WP_MatchesMapRegex { } -?> \ No newline at end of file +?> diff --git a/wp-includes/query.php b/wp-includes/query.php index 79c4038e5..549b942dd 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -1452,37 +1452,38 @@ class WP_Query extends WP_Object_Query { if ( !empty($q['taxonomy']) && !empty($q['term']) ) { $tax_query[] = array( 'taxonomy' => $q['taxonomy'], - 'terms' => $q['term'], + 'terms' => array( $q['term'] ), + 'field' => 'slug', ); - } + } else { + foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy => $t ) { + if ( $t->query_var && !empty( $q[$t->query_var] ) ) { + $tax_query_defaults = array( + 'taxonomy' => $taxonomy, + 'field' => 'slug', + 'operator' => 'IN' + ); - foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy => $t ) { - if ( $t->query_var && !empty( $q[$t->query_var] ) ) { - $tax_query_defaults = array( - 'taxonomy' => $taxonomy, - 'field' => 'slug', - 'operator' => 'IN' - ); + if ( $t->rewrite['hierarchical'] ) { + $q[$t->query_var] = basename($q[$t->query_var]); + if ( $taxonomy == $q['taxonomy'] ) + $q['term'] = basename($q['term']); + } - if ( $t->rewrite['hierarchical'] ) { - $q[$t->query_var] = basename($q[$t->query_var]); - if ( $taxonomy == $q['taxonomy'] ) - $q['term'] = basename($q['term']); - } + $term = $q[$t->query_var]; - $term = $q[$t->query_var]; - - if ( strpos($term, '+') !== false ) { - $terms = preg_split( '/[+\s]+/', $term ); - foreach ( $terms as $term ) { + if ( strpos($term, '+') !== false ) { + $terms = preg_split( '/[+\s]+/', $term ); + foreach ( $terms as $term ) { + $tax_query[] = array_merge( $tax_query_defaults, array( + 'terms' => array( $term ) + ) ); + } + } else { $tax_query[] = array_merge( $tax_query_defaults, array( - 'terms' => array( $term ) + 'terms' => preg_split('/[,\s]+/', $term) ) ); } - } else { - $tax_query[] = array_merge( $tax_query_defaults, array( - 'terms' => preg_split('/[,\s]+/', $term) - ) ); } } }