Manually Extract a Single Site from a WordPress Multisite using wp-cli

How to extract a stand-alone WordPress website from an existing multisite installation. The process here uses wp-cli. But one could achieve the same results using and db import/export tool such as phpmyadmin or https://github.com/10up/MU-Migration.

If you need any help moving sites into or out of a multisite, let me know!

Create new stand alone website

First create the new stand alone WordPress website (not multisite) and run the WordPress installer.

Import the multisite DB into the single site

Export the entire multisite database from the multisite WordPress installation.

wp db export multisite.sql

Then import the database over the single site installation.

wp db import multisite.sql

Find the website to extract

View the imported database with a database UI such as phpmyadmin, adminer, etc.

Look at the wp_options tables in order to find the site you want to extract e.g. wp_10_options. The 1st rows of each options table will show you the domain name associated with the sub-site that you wish to use.

Edit tables

Rename the wp_users and wp_usersmeta tables to match the multisite number e.g. wp_10_users, wp_10_usersmeta.

Delete the remaining unused tables e.g. everything that does not start with wp_10_

Edit the wp-config.php

Set the WordPress wp-config.php $table_prefix variable to the new table prefix e.g. from wp_ to wp_10_

$table_prefix = 'wp_10_';

Move Assets

Copy the required wp-content assets from the multisite to the new site. Copy the themes, plugins and mu-plugins to the new site.

You may need to delete plugins or mu-plugins that are only intended for multisite websites.

Copy the uploads from the multisite to the new site. These are in the uploads/sites/#/ directory. The number here will match the site number you previously extracted from the database e.g. uploads/sites/10/

Search & Replace

Perform any necessary search-replace operations.
Replace code example # with the multisite’s number.

wp search-replace site.com site.test
wp search-replace old/path/ new/path
wp search-replace uploads/sites/#/ uploads/

Done!

Your new WordPress site should be extracted and accessible from the multisite.

You may need to reenable or delete plugins, and update or delete users from wp-admin.

Troubleshooting FAQ

Update your user via wp-cli

wp user update USER --role=administrator

Or create a new user via wp-cli

wp user create USER --role=administrator


Posted

in

,