To copy a subdomain site from one WordPress Multisite network to another using WP-CLI, you can follow these steps:
- Export the source site’s content using
wp export
:
On the source server, navigate to the root directory of your WordPress installation and run:
wp export --url=source-site.example.com --dir=/path/to/export/directory
This will create an XML file containing all the content from the source site.
- Compress the source site’s
wp-content/uploads
directory:
Still on the source server, compress the wp-content/uploads
directory, as you’ll need to transfer it to the destination server:
tar czvf uploads.tar.gz /path/to/wordpress/wp-content/uploads
- Transfer the exported content and the compressed
uploads
directory to the destination server:
You can use a tool like scp
or an FTP client to transfer the exported XML file and the compressed uploads.tar.gz
file to the destination server.
- Import the content on the destination site:
On the destination server, navigate to the root directory of your WordPress installation and run:
wp import /path/to/exported/content/file.xml --authors=create --url=destination-site.example.com
This command will import the content and create new users if necessary.
- Uncompress the transferred
uploads
directory:
Still on the destination server, uncompress the uploads.tar.gz
file to the wp-content/uploads
directory:
tar xzvf uploads.tar.gz -C /path/to/wordpress/wp-content
- Update the site URL and other configurations (optional):
If you need to update the site URL, search and replace the old URL with the new URL using wp search-replace
:
wp search-replace 'https://source-site.example.com' 'https://destination-site.example.com' --url=destination-site.example.com
Remember to replace the URLs with your actual domain names. Also, note that this command will only update the database content; if there are hardcoded URLs in your theme or plugin files, you’ll need to update them manually.