Convert a Multisite WordPress install into a Single site

I’ve gone through the steps to extract a site from a multisite install to a single instance now:

  1. Set up a clean copy of WP but don’t install it
  2. Find the site ID
  3. Copy the files from blogs.dir/ID/files to the new WP uploads folder
  4. Copy the theme the site uses and any plugins it uses to the appropriate folders in the new wp-content folder
  5. Take a back up of the multisite database but only the tables for the target site and the users and usermeta tables using MySQL workbench or equivalent
  6. Restore the backup to a new database and change the table name prefixes so they are all the same eg. ‘wp_SITEID_’ to ‘wp_’
  7. Using MySQL workbench or query browser tidy up the users and usermeta tables like so:
    1. DELETE FROM wp_usermeta WHERE user_id NOT IN( SELECT distinct(user_id) FROM wp_usermeta where meta_key LIKE 'wp_SITEID_%' );
    2. DELETE FROM wp_users WHERE ID NOT IN( SELECT distinct(user_id) FROM wp_usermeta where meta_key LIKE 'wp_SITEID_%' );
    3. UPDATE wp_usermeta SET meta_key = REPLACE( meta_key, 'wp_SITEID_', 'wp_' ) WHERE meta_key LIKE 'wp_SITEID_%';
    4. UPDATE wp_options SET option_name = REPLACE( option_name, 'wp_SITEID_', 'wp_' ) WHERE option_name LIKE 'wp_SITEID_%';
  8. Begin the WP install process to create a wp-config.php but don’t click ‘Run the install’
  9. Create a default .htaccess file if permalinks were in use or just visit the permalinks page in wp-admin
  10. You’ll need to update any old URLs in your database next. Ideally use a safe search/replace tool like the one in wp-cli or its general purpose precursor search/replace db by interconnect/it. Specifically replace blogs.dir/SITE_ID/files with uploads, and if you’re changing your site URL search for oldsite.com and replace with newsite.com.

A fair bit of effort and you have to be careful with the database edits but that’s the only I can see to extract a single site from an existing multisite with all its settings etc… intact.

EDIT:

As spotted by @Jake I forgot to mention the final steps you may need to take eg. search/replace of old URLs. I’ve updated the list accordingly.

Leave a Comment