Use WP-CLI to Migrate Posts from One Database to Another

Migrate Posts from One WordPress Database to Another Using WP-CLI

  1. Export the posts from the source site. You can use the wp export command to do this:
$ wp export --post__in=123,124,125

In the command above, replace 123,124,125 with the IDs of the posts you want to export. This will create an XML file that contains the data for these posts. You don’t have to specify the XML file, it’s created automatically and its filename is revealed after you run the above command.

  1. Import the posts to the destination site. You can use the wp import command to do this:
$ wp import example.wordpress.2023-06-24.xml --authors=create

In the command above, replace example.wordpress.2023-06-24.xml with the name of the XML file you created in step 1. This will import the posts into the destination site. The –author=create parameter will create an author if one doesn’t exist.

These commands should be run from the root directory of the WordPress installation, and you should replace the placeholder values with your actual data.

Alternative Method

mysqldump -u root -p database –where=”post_parent=123″ > posts.sql

mysql < posts.sql