From 0407057fece6243332fcaf579522fc911bcca989 Mon Sep 17 00:00:00 2001 From: dd32 Date: Sun, 28 Feb 2010 02:49:01 +0000 Subject: [PATCH] Dont clobber taxonomy intersections/unions. Only redirects to the canonical url if only one term has been queried. Props scribu for some of the commit. See #8948 git-svn-id: http://svn.automattic.com/wordpress/trunk@13480 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/canonical.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index ab9a20d5a6..0996419f34 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -132,18 +132,27 @@ function redirect_canonical($requested_url=null, $do_redirect=true) { $author = get_userdata(get_query_var('author')); if ( false !== $author && $redirect_url = get_author_posts_url($author->ID, $author->user_nicename) ) $redirect['query'] = remove_query_arg('author', $redirect['query']); - } + } elseif ( is_category() || is_tag() || is_tax() ) { // Terms (Tags/categories) + + $term_count = 0; + foreach ( array('category__in', 'category__not_in', 'category__and', 'post__in', 'post__not_in', + 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and') as $key ) + $term_count += count($wp_query->query_vars[$key]); - // Terms (Tags/categories) - if ( is_category() || is_tag() || is_tax() ) { $obj = $wp_query->get_queried_object(); - if ( !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) ) && !is_wp_error($tax_url) ) { - $redirect['query'] = remove_query_arg( array( 'category_name', 'tag', 'cat', 'tag_id', 'term', 'taxonomy'), $redirect['query']); - if ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too: + if ( $term_count > 1 && !empty($obj->term_id) && ( $tax_url = get_term_link((int)$obj->term_id, $obj->taxonomy) ) && !is_wp_error($tax_url) ) { + + if ( is_category() ) { + $redirect['query'] = remove_query_arg( array( 'category_name', 'category', 'cat'), $redirect['query']); + } elseif ( is_tag() ) { + $redirect['query'] = remove_query_arg( array( 'tag', 'tag_id'), $redirect['query']); + } elseif ( is_tax() ) { // Custom taxonomies will have a custom query var, remove those too: $tax = get_taxonomy( $obj->taxonomy ); if ( false !== $tax->query_var) $redirect['query'] = remove_query_arg($tax->query_var, $redirect['query']); + else + $redirect['query'] = remove_query_arg( array( 'term', 'taxonomy'), $redirect['query']); } $tax_url = parse_url($tax_url);