Make WordPress Core

Opened 13 years ago

Closed 13 years ago

#18318 closed defect (bug) (duplicate)

Slug changes for pages do not redirect (like posts do) — at Version 1

Reported by: varun21's profile varun21 Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2.1
Component: Canonical Keywords: needs-patch
Focuses: Cc:

Description (last modified by dd32)

Alert: Newbie trac user :). Already tried searching for existing bugs

Steps to reproduce this issue:

  1. Publish a page.
  2. disable canonical redirects. Pretty permalinks enabled. Clean install of WP with no plugins.
  3. Change the page slug
  4. Old slug does not redirect to the new slug (only when post_type is page).

Code suspected to be the cause:
/wp-includes/query.php
function wp_old_slug_redirect
line 3488:

//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';

The trouble is pagename in $wp_query->query_varspagename? is never set/found, so the guess for post_type always guesses the post_type as a 'post'. Thus when a page redirect is expected, the query doesn't fetch any results.

example query vars for post expecting redirection

Array ( [page] => 0 [name] => sample-post-with-threaded-comments [error] => [m] => 0 [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [static] => [pagename] => [page_id] => 0 [second] => [minute] => [hour] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [category_name] => [tag] => [cat] => [tag_id] => [author_name] => [feed] => [tb] => [paged] => 0 [comments_popup] => [meta_key] => [meta_value] => [preview] => [s] => [sentence] => [fields] => [category__in] => Array ( ) [category__not_in] => Array ( ) [category__and] => Array ( ) [post__in] => Array ( ) [post__not_in] => Array ( ) [tag__in] => Array ( ) [tag__not_in] => Array ( ) [tag__and] => Array ( ) [tag_slug__in] => Array ( ) [tag_slug__and] => Array ( ) [ignore_sticky_posts] => [suppress_filters] => [cache_results] => 1 [update_post_term_cache] => 1 [update_post_meta_cache] => 1 [post_type] => [posts_per_page] => 10 [nopaging] => [comments_per_page] => 50 [no_found_rows] => [order] => DESC ) 

example query vars for page expecting redirection
Array ( [page] => 0 [name] => sumedh [error] => [m] => 0 [p] => 0 [post_parent] => [subpost] => [subpost_id] => [attachment] => [attachment_id] => 0 [static] => [pagename] => [page_id] => 0 [second] => [minute] => [hour] => [day] => 0 [monthnum] => 0 [year] => 0 [w] => 0 [category_name] => [tag] => [cat] => [tag_id] => [author_name] => [feed] => [tb] => [paged] => 0 [comments_popup] => [meta_key] => [meta_value] => [preview] => [s] => [sentence] => [fields] => [category__in] => Array ( ) [category__not_in] => Array ( ) [category__and] => Array ( ) [post__in] => Array ( ) [post__not_in] => Array ( ) [tag__in] => Array ( ) [tag__not_in] => Array ( ) [tag__and] => Array ( ) [tag_slug__in] => Array ( ) [tag_slug__and] => Array ( ) [ignore_sticky_posts] => [suppress_filters] => [cache_results] => 1 [update_post_term_cache] => 1 [update_post_meta_cache] => 1 [post_type] => [posts_per_page] => 10 [nopaging] => [comments_per_page] => 50 [no_found_rows] => [order] => DESC ) 

Change History (1)

#1 @dd32
13 years ago

  • Component changed from General to Canonical
  • Description modified (diff)
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

See #4328 (If you know a ticket exists, you can usually find it by searching in a specific component - searching for old tickets isn't exactly simple for new trac users)

Note: See TracTickets for help on using tickets.