Make hierarchical URLs work for any hierarchical taxonomy. See #12659

git-svn-id: http://svn.automattic.com/wordpress/trunk@15732 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
scribu 2010-10-06 11:04:03 +00:00
parent a8367fa6f2
commit 38888b588d
2 changed files with 22 additions and 32 deletions

View File

@ -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(

View File

@ -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,