From 1027248cee5ecd9a9577d88d448c8a351ad1713f Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Tue, 19 Oct 2010 10:27:34 +0000 Subject: [PATCH] Limit wp_old_slug_redirect() to redirecting to only posts of the same post_type kind. See #15140 git-svn-id: https://develop.svn.wordpress.org/trunk@15848 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/query.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index c4f428fb90..db2441122b 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -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