From 7a6b978b7f8b3947e224c86896d0bb02c4e912cc Mon Sep 17 00:00:00 2001 From: duck_ Date: Tue, 21 Feb 2012 19:00:06 +0000 Subject: [PATCH] Ensure that a category is part of the query before redirecting permalink structures containing %category%. Fixes #19241. This fixes incorrect canonical redirects for singular queries using custom rewrite rules. git-svn-id: http://svn.automattic.com/wordpress/trunk@19970 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/canonical.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index b627a78c4..57cc31425 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -191,8 +191,8 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) { } } - } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false ) { - $category = get_category_by_path(get_query_var('category_name')); + } elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false && $cat = get_query_var( 'category_name' ) ) { + $category = get_category_by_path( $cat ); $post_terms = wp_get_object_terms($wp_query->get_queried_object_id(), 'category', array('fields' => 'tt_ids')); if ( (!$category || is_wp_error($category)) || ( !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms) ) ) $redirect_url = get_permalink($wp_query->get_queried_object_id()); @@ -494,4 +494,4 @@ function wp_redirect_admin_locations() { } } -add_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 ); \ No newline at end of file +add_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 );