MultiSite Blog ID Issues?
Let’s be honest, if you’ve ever worked with WordPress MultiSite, you know it can be a real PITA to work with. If your workflow involves using a Development server and then moving to your Production server, take care to make sure the Blog IDs are synced. This can be especially challenging if you have a small team. You must take care to add the sites to both your development server and production server in the same sequence. Otherwise, you’ll have a mess on your hands that could take some time to clear up. This guide will hopefully save you some time.
Transfer MultiSite Sites Between Servers
Before we get started, if you don’t want to go through the hassle of moving it yourself manually, may I suggest Prime Mover? The URL follows: https://wordpress.org/plugins/prime-mover/
MultiSite – Blog ID Sync Issue – Scenario
Probably the easiest way to “fix” this, is to update your Dev Server to match the IDs on your Production. For example, say you have three sites
Site Name | Blog ID – Production | Blog ID – Development |
Site A | 1 | 2 |
Site B | 2 | 1 |
Site C | 3 | 3 |
So given this, what you could do is export all of your sites from Prime Mover, and then change the site information accordingly on your Dev server to match with Production and then restore the file based on ID number. After the restore, your sites will match Blog ID and content.
This plugin works extremely well as long as you don’t have missing blog IDs/Site Numbers. What do I mean by this? Say on your Production server, a user deleted and old site that had a Blog ID of 2. Maybe this existed before you had your workflow down on your Development server. You’ve just done a bunch of work on Site B and need to get it onto your server. Consider the following example:
Site Name | Blog ID – Production | Blog ID – Development |
Site A | 1 | 1 |
Site B | 4 | 2 |
Site C | 3 | 3 |
You fire up Prime Mover and export it out. The Blog ID is 2 on your Development Server, but it has a Blog ID of 4 on your Production server because an old site that had that ID has been deleted. The issue is that if you try to restore the site with Blog ID 2 from Dev, to Blog ID 4 on your Production server, Prime Mover will not let you do it because the Blog ID values are different. This is a good protection mechanism to stop someone from shooting themselves in the foot, but you are now in a pickle…what to do?
MultiSite – Blog ID Sync Issue – Cure
If you know your way around the MySQL/MariaDB, you can do a little triage to whip your sites back into shape. Before doing any of this, make sure your back up your MultiSite and database. Yes, it adds more time to complete this, but if you end up hosing this, you can recover. If not, you will be in a worse mess than when you started!
UPDATE wp_blogs SET blog_id = 2 WHERE blog_id = 4; RENAME TABLE wp_4_commentmeta TO wp_2_commentmeta; RENAME TABLE wp_4_comments TO wp_2_comments; RENAME TABLE wp_4_links TO wp_2_links; RENAME TABLE wp_4_options TO wp_2_options; RENAME TABLE wp_4_postmeta TO wp_2_postmeta; RENAME TABLE wp_4_posts TO wp_2_posts; RENAME TABLE wp_4_term_relationships TO wp_2_term_relationships; RENAME TABLE wp_4_term_taxonomy TO wp_2_term_taxonomy; RENAME TABLE wp_4_termmeta TO wp_2_termmeta; RENAME TABLE wp_4_terms TO wp_2_terms; ALTER TABLE wp_blogs AUTO_INCREMENT = 3;
Let’s discuss what we are doing here. First of all, we are going to set Blog ID 4 to the missing Blog ID 2 to match our Dev server. Then we need to rename the WP tables for that site to match the Blog ID (2). After that, we set AUTO_INCREMENT to 3, which will be our highest numbered site after the move so subsequent sites get numbered correctly. Once this is complete, you can restore your backup file generated by Prime Mover and import all of your hard work you completed on your Dev Server.
Hopefully this will help some unlucky soul who was not aware of how WordPress MultiSite works under the hood. If this helps avoid some frustration and to meet a deadline to get your work from Development to Production, then you are welcome!