Make a database backup first!
您可以在主题的
functions.php
并执行一次。
喜欢https://your.site/?old_parent=100&new_parent=200
其中,100是旧父页Id,200是要为旧父页的子页设置的新父页Id。
设置您自己的ID!(id是URL中的一个数字值,例如,当您编辑帖子\\页面时http://yoursite.test/wp-admin/post.php?post=54&action=edit - 页码id为54)
function custom_replace_parent() {
$old_parent_post_id = intval( $_GET[\'old_parent\'] );
$new_parent_post_id = intval( $_GET[\'new_parent\'] );
if( $old_parent_post_id < 1 ) {return;}
$child_pages = get_posts(
array(
\'post_type\' => \'page\',
\'post_status\' => \'any\',
\'posts_per_page\' => -1,
\'post_parent\' => $old_parent_post_id,
)
);
foreach ( $child_pages as $child_page ) {
wp_update_post(
array(
\'ID\' => $child_page->ID,
\'post_parent\' => $new_parent_post_id,
)
);
}
}
add_action( \'init\', \'custom_replace_parent\' );
如果遇到PHP最大执行时间,只需刷新一个页面(如果此单亲页面有数千个子页面,则可能会出现这种情况)。
Important! Remove this code out of your site\'s functions.php after you\'ll finish
And again, make a backup first!
这段代码的思想是放置,然后使用示例中的GET参数替换刷新站点,但使用页面ID,而不是
this code MUST be removed from site.
If you will not remove this code after you\'ve done fixing it may make harm. as really anyone who might guess that this code is installed on your site will be able to perform these actions, ruining your website!