From d6e6296b89f71643c91031f027214f971d9838d0 Mon Sep 17 00:00:00 2001 From: scribu Date: Wed, 6 Oct 2010 11:04:03 +0000 Subject: [PATCH] Make hierarchical URLs work for any hierarchical taxonomy. See #12659 git-svn-id: https://develop.svn.wordpress.org/trunk@15732 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/query.php | 51 ++++++++++++++++------------------------ wp-includes/taxonomy.php | 3 ++- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index a78316bc9f..f7bbe66045 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -1486,29 +1486,31 @@ class WP_Query extends WP_Object_Query { function parse_tax_query( $q ) { $tax_query = array(); - if ( $this->is_tax ) { - 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' + ); - $term = str_replace( ' ', '+', $q[$t->query_var] ); + $term = urlencode( urldecode( $q[$t->query_var] ) ); - 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 { + if ( $t->hierarchical_url ) { + $tax_query[] = array_merge( $tax_query_defaults, array( + 'terms' => array( basename( str_replace( '%2F', '/', $term ) ) ) + ) ); + } elseif ( strpos($term, '+') !== false ) { + $terms = preg_split( '/[+\s]+/', $term ); + foreach ( $terms as $term ) { $tax_query[] = array_merge( $tax_query_defaults, array( - 'terms' => preg_split('/[,\s]+/', $term) + 'terms' => array( $term ) ) ); } + } else { + $tax_query[] = array_merge( $tax_query_defaults, array( + 'terms' => preg_split('/[,\s]+/', $term) + ) ); } } } @@ -1552,19 +1554,6 @@ class WP_Query extends WP_Object_Query { ); } - // Category stuff for nice URLs - if ( '' != $q['category_name'] && !$this->is_singular ) { - $q['category_name'] = str_replace( '%2F', '/', urlencode(urldecode($q['category_name'])) ); - $q['category_name'] = '/' . trim( $q['category_name'], '/' ); - - $tax_query[] = array( - 'taxonomy' => 'category', - 'terms' => array( basename( $q['category_name'] ) ), - 'operator' => 'IN', - 'field' => 'slug' - ); - } - // Tag stuff if ( !empty($qv['tag_id']) ) { $tax_query[] = array( diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 9e455c27b6..1b715a092e 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -17,8 +17,9 @@ function create_initial_taxonomies() { register_taxonomy( 'category', 'post', array( 'hierarchical' => true, + 'hierarchical_url' => true, 'update_count_callback' => '_update_post_term_count', - 'query_var' => false, + 'query_var' => 'category_name', 'rewrite' => false, 'public' => true, 'show_ui' => true,