Limit wp_old_slug_redirect() to redirecting to only posts of the same post_type kind. See #15140

git-svn-id: http://svn.automattic.com/wordpress/trunk@15848 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dd32 2010-10-19 10:27:34 +00:00
parent 0c56811154
commit 0c1eb68663
1 changed files with 9 additions and 1 deletions

View File

@ -3146,7 +3146,15 @@ function wp_old_slug_redirect() {
if ( is_404() && '' != $wp_query->query_vars['name'] ) :
global $wpdb;
$query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND meta_key = '_wp_old_slug' AND meta_value=%s", $wp_query->query_vars['name']);
// Guess the current post_type based on the query vars.
if ( get_query_var('post_type') )
$post_type = get_query_var('post_type');
elseif ( !empty($wp_query->query_vars['pagename']) )
$post_type = 'page';
else
$post_type = 'post';
$query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta, $wpdb->posts WHERE ID = post_id AND post_type = %s AND meta_key = '_wp_old_slug' AND meta_value = %s", $post_type, $wp_query->query_vars['name']);
// if year, monthnum, or day have been specified, make our query more precise
// just in case there are multiple identical _wp_old_slug values