6

It took me great time today to convert one site from https://example.com to https://sub.example2.com from WordPress multiste installation to normal WordPress installation (read: singlesite).

Since I started using wp-cli recently I thought it will be possible to do it only with wp-cli.

I used wp-cli to export a database. Since my instance was prefixed as: wp_9_

I used the code like this:

wp db export --tables="wp_users, wp_usermeta, wp_9_posts, wp_9_comments, wp_9_links, wp_9_options, wp_9_postmeta, wp_9_terms, wp_9_term_taxonomy, wp_9_term_relationships, wp_9_termmeta, wp_9_commentmeta" 

While I later found I should use something like this:

wp db export --tables=wp_users,wp_usermeta, $(wp db tables --all-tables-with-prefix 'wp_9' --format=csv --allow-root) --allow-root

For those not using the #

wp db export --tables=wp_users,wp_usermeta, $(wp db tables --all-tables-with-prefix 'wp_9' --format=csv) 

Then I set:

define('WP_HOME','https://sub.example2.com');
define('WP_SITEURL','https://sub.example2.com'); 

But I faced the problem: posts, guids, and meta not updated... Usually I never do the next step since it just works in numerous instances.

But I was forced to do the following:

UPDATE wp_posts SET post_content = replace(post_content, 'https://example.com', 'https://sub.example2.com');
UPDATE wp_posts SET guid = replace(guid, 'https://example.com', 'https://sub.example2.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'https://example.com', 'https://sub.example2.com');

Even further, I needed to update the uploads path, in the post content and even in the post_meta, since on mulitsite the uploads path was /uploads/sites/9/ while on a single site only /uploads/.

This should also reflect in the posts and post meta like this:

UPDATE wp_posts SET post_content = replace(post_content, '/uploads/sites/9/', '/uploads/');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'/uploads/sites/9/', '/uploads/');

After this step, I manually copied files from /uploads/sites/9/ folder to the /uploads/ folder of the new WordPress instance on the same server using the cp command. Sadly, I haven't even considered wp-cli for that.

I am asking is it possible to automate this processes entirely using wp-cli? It would be a great helper next time.

3 Answers 3

3

Try using the 10up/MU-Migration command: https://github.com/10up/MU-Migration

1
  • this seams like the solution. i will check it soon and mark it as it seams like most helpful.
    – prosti
    Commented May 6, 2016 at 16:47
1

If your multi-site install only has a small number of subsites, you might find it easier to just use the export and import tools from the administration area.

For each site in the multi site install, you can download an export file that contains blog posts, pages, users, comments etc. Then you can import all these into the same single site. Might be easier than fiddling with the database...

3
  • 1
    the possible problem with this solution is when the original domain is not available. You know for the wpcom-themes.svn.automattic.com/demo/theme-unit-test-data.xml, there you have images like wpthemetestdata.files.wordpress.com/2010/08/manhattansummer.jpg but when the domain wpthemetestdata.files.wordpress.com is not available any more the whole thing with resources may not work.
    – prosti
    Commented May 6, 2016 at 16:44
  • 1
    maybe we will also have a way to export a big fat zip file one day but i am not sure right now if this exists, but could be possible since I think xml file can enclose binary data.
    – prosti
    Commented May 6, 2016 at 16:50
  • True. The few times I've moved and merged sites this way (or broken up sites into multiple site by category/author), I've only deleted the original posts AFTER the new copies have imported the images during import. The export file doesn't make a good permanent backup.
    – ToniWidmo
    Commented May 8, 2016 at 18:23
0

Instead of doing those MySQL UPDATE commands you can use WP-CLI's wp search-replace command.

Example: wp search-replace 'https://example.com' 'https://sub.example2.com'

This is a serialisation-safe search and replace, so your meta won't get borked.

More info at http://wp-cli.org/commands/search-replace/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.