Attempt canonical redirect only for public post types. Props solarissmoke. see #13125

git-svn-id: https://develop.svn.wordpress.org/trunk@14595 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2010-05-13 15:09:43 +00:00
parent a56d439b4d
commit 402b875b3d
1 changed files with 8 additions and 3 deletions

View File

@ -83,9 +83,14 @@ function redirect_canonical($requested_url=null, $do_redirect=true) {
if ( is_404() ) {
// Redirect ?page_id, ?p=, ?attachment_id= to their respective url's
$id = max( get_query_var('p'), get_query_var('page_id'), get_query_var('attachment_id'));
if ( $id && $redirect_url = get_permalink($id) )
$redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id'), $redirect['query']);
$id = max( get_query_var('p'), get_query_var('page_id'), get_query_var('attachment_id') );
if ( $id && $redirect_post = get_post($id) ) {
$post_type_obj = get_post_type_object($redirect_post->post_type);
if ( $post_type_obj->public ) {
$redirect_url = get_permalink($redirect_post);
$redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id'), $redirect['query']);
}
}
if ( ! $redirect_url )
$redirect_url = redirect_guess_404_permalink();