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
This commit is contained in:
duck_ 2012-02-21 19:00:06 +00:00
parent 206bd59baa
commit 7a6b978b7f
1 changed files with 3 additions and 3 deletions

View File

@ -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 );
add_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 );