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 ) {
|
function parse_tax_query( $q ) {
|
||||||
$tax_query = array();
|
$tax_query = array();
|
||||||
|
|
||||||
if ( $this->is_tax ) {
|
foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy => $t ) {
|
||||||
foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy => $t ) {
|
if ( $t->query_var && !empty( $q[$t->query_var] ) ) {
|
||||||
if ( $t->query_var && !empty( $q[$t->query_var] ) ) {
|
$tax_query_defaults = array(
|
||||||
$tax_query_defaults = array(
|
'taxonomy' => $taxonomy,
|
||||||
'taxonomy' => $taxonomy,
|
'field' => 'slug',
|
||||||
'field' => 'slug',
|
'operator' => 'IN'
|
||||||
'operator' => 'IN'
|
);
|
||||||
);
|
|
||||||
|
|
||||||
$term = str_replace( ' ', '+', $q[$t->query_var] );
|
$term = urlencode( urldecode( $q[$t->query_var] ) );
|
||||||
|
|
||||||
if ( strpos($term, '+') !== false ) {
|
if ( $t->hierarchical_url ) {
|
||||||
$terms = preg_split( '/[+\s]+/', $term );
|
$tax_query[] = array_merge( $tax_query_defaults, array(
|
||||||
foreach ( $terms as $term ) {
|
'terms' => array( basename( str_replace( '%2F', '/', $term ) ) )
|
||||||
$tax_query[] = array_merge( $tax_query_defaults, array(
|
) );
|
||||||
'terms' => array( $term )
|
} elseif ( strpos($term, '+') !== false ) {
|
||||||
) );
|
$terms = preg_split( '/[+\s]+/', $term );
|
||||||
}
|
foreach ( $terms as $term ) {
|
||||||
} else {
|
|
||||||
$tax_query[] = array_merge( $tax_query_defaults, array(
|
$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
|
// Tag stuff
|
||||||
if ( !empty($qv['tag_id']) ) {
|
if ( !empty($qv['tag_id']) ) {
|
||||||
$tax_query[] = array(
|
$tax_query[] = array(
|
||||||
|
@ -17,8 +17,9 @@
|
|||||||
function create_initial_taxonomies() {
|
function create_initial_taxonomies() {
|
||||||
register_taxonomy( 'category', 'post', array(
|
register_taxonomy( 'category', 'post', array(
|
||||||
'hierarchical' => true,
|
'hierarchical' => true,
|
||||||
|
'hierarchical_url' => true,
|
||||||
'update_count_callback' => '_update_post_term_count',
|
'update_count_callback' => '_update_post_term_count',
|
||||||
'query_var' => false,
|
'query_var' => 'category_name',
|
||||||
'rewrite' => false,
|
'rewrite' => false,
|
||||||
'public' => true,
|
'public' => true,
|
||||||
'show_ui' => true,
|
'show_ui' => true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user