Swap out a page that is a parent to a many many pages

Make a database backup first!

You can create such code in theme’s functions.php and execute it once.

like https://your.site/?old_parent=100&new_parent=200

Where 100 is old parent page Id and 200 new parent page id you’d like to set for child pages of old parent page.

Set your own IDs! (id is a numerical value in URL when you edit post\page for example http://yoursite.test/wp-admin/post.php?post=54&action=edit – page id is 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' );

If you’ll hit PHP max execution time, just refresh a page (it may happen if you have thousands of child pages for this single parent page).

Important! Remove this code out of your site’s functions.php after you’ll finish

And again, make a backup first!

The idea of this code is to be put, then you do replacements refreshing your site with GET parameters as in example but with your page ids in place, than 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!