WP Multisite to single WordPress manual installation
This post was made after a very intense session of 6 hours trying, without luck, to export a wp multisite site using the WordPress tools and plugins. So I decided to do it manually like a real man.
Well, now follow the steps below to extract a subsite from a Multisite Installation:
1 – Identifying the wp multisite’s subsite
- Go to your WordPress network admin dashboard (https://example.com/wp-admin/network).
- Go to ‘Sites‘.
- Click in the site you want to export.
- See the URL in your browser (https://example.com/wp-admin/network/site-info.php?id=3).
The site ID is 3.
2 – Export the wp multisite database
- Install the plugin ‘Adminer‘.
- Go to ‘Tools » Adminer‘.
- Click in ‘Start Adminer inside‘.
- Go to ‘Export‘.
- Deselect all the tables and select only the ones starting with ‘wp_3_‘.
- Select ‘wp_usermeta‘ and ‘wp_users‘.
- Click in the button ‘Export‘.
3 – Edit the *.sql file
- Open the downloaded sql file with your favourite code editor.
- Find and replace ‘/uploads/sites/3/‘ with ‘/uploads/‘.
- Find and replace the URL of the old subsite with the new URL for the single site.
- If you think you need to find and replace something else to fit your new installation, this is the moment.
4 – Upload the *.sql file
- Create a new database in your server as usual for a new WordPress site.
- Import the modified sql of the last stage.
- Perform this SQL Query ```sql – delete any usermeta specific to the other subsites delete from wp_usermeta where meta_key regexp ‘^wp_([0-9]+)_’;
– duplicate the wp_usermeta structure in a working data table, – but add a unique index for filtering out duplicates create table _fix_usermeta like wp_usermeta; alter table _fix_usermeta add unique (user_id, meta_key);
– copy the site-specific usermeta, keeping only the last of each duplicate insert into _fix_usermeta select * from wp_usermeta where meta_key like ‘wp_%’ order by user_id, meta_key, umeta_id on duplicate key update umeta_id= values (umeta_id), meta_value= values (meta_value);
– remove the first of each duplicate delete from wp_usermeta where meta_key like ‘wp_%’ and not exists(select * from _fix_usermeta where umeta_id = wp_usermeta.umeta_id);
– remove that working data table drop table _fix_usermeta; ```
5 – Prepare the file structure for the new site
- Download and copy the files for a new WordPress installation.
- Copy all the plugins and themes folders from the Multisite to the new site.
- Copy ‘/media/sites/3‘ to ‘/wp-content/uploads‘ in the new site.
6 – Et voilà!
- Enter in your new site dashboard and check everything works good.