Fix page permalink 404 when pages are reordered. Props David House. fixes #2071
git-svn-id: http://svn.automattic.com/wordpress/trunk@3356 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d3105dc988
commit
541c30cc70
|
@ -370,7 +370,7 @@ class WP_Query {
|
|||
$page_path .= ($pathdir!=''?'/':'') . sanitize_title($pathdir);
|
||||
|
||||
$all_page_ids = get_all_page_ids();
|
||||
$reqpage = 0;
|
||||
$reqpage = 0;
|
||||
foreach ( $all_page_ids as $page_id ) {
|
||||
$page = get_page($page_id);
|
||||
if ( $page->fullpath == $page_path ) {
|
||||
|
|
|
@ -769,18 +769,37 @@ function add_ping($post_id, $uri) { // Add a URI to those already pung
|
|||
return $wpdb->query("UPDATE $wpdb->posts SET pinged = '$new' WHERE ID = $post_id");
|
||||
}
|
||||
|
||||
//fetches the pages returned as a FLAT list, but arranged in order of their hierarchy, i.e., child parents
|
||||
//immediately follow their parents
|
||||
function get_page_hierarchy($posts, $parent = 0) {
|
||||
$result = array ( );
|
||||
if ($posts) { foreach ($posts as $post) {
|
||||
if ($post->post_parent == $parent) {
|
||||
$result[$post->ID] = $post->post_name;
|
||||
$children = get_page_hierarchy($posts, $post->ID);
|
||||
$result += $children; //append $children to $result
|
||||
}
|
||||
} }
|
||||
return $result;
|
||||
}
|
||||
|
||||
function generate_page_rewrite_rules() {
|
||||
global $wpdb;
|
||||
$posts = $wpdb->get_results("SELECT ID, post_name FROM $wpdb->posts WHERE post_status = 'static' ORDER BY post_parent DESC");
|
||||
|
||||
//get pages in order of hierarchy, i.e. children after parents
|
||||
$posts = get_page_hierarchy($wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_status = 'static'"));
|
||||
//now reverse it, because we need parents after children for rewrite rules to work properly
|
||||
$posts = array_reverse($posts, true);
|
||||
|
||||
$page_rewrite_rules = array();
|
||||
|
||||
if ($posts) {
|
||||
foreach ($posts as $post) {
|
||||
|
||||
foreach ($posts as $id => $post) {
|
||||
// URI => page name
|
||||
$uri = get_page_uri($post->ID);
|
||||
$uri = get_page_uri($id);
|
||||
|
||||
$page_rewrite_rules[$uri] = $post->post_name;
|
||||
$page_rewrite_rules[$uri] = $post;
|
||||
}
|
||||
|
||||
update_option('page_uris', $page_rewrite_rules);
|
||||
|
|
Loading…
Reference in New Issue