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
This commit is contained in:
parent
448f74675a
commit
d6e6296b89
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue