Jan 31 2012

Howto: Transfer Data Between WordPress Blogs (Export/Import)

When I started my blog, I first tried all kinds of things locally as I had WordPress installed on my Synology DS211j. It served as a sandbox where I could experiment without being afraid of breaking something in production. When I had tweaked my WordPress installation to my needs I installed it on the actual server where it would reside. As I experimented, I wrote blog posts about the things that I found out. Now I needed to transfer the blog posts (as well as other meta data) from the old WordPress to the new one.  There are many options to do this, I introduce two here.

WordPress Export/Import

If you are allergic to database operations, this option is for you. It is not perfect, especially if you have a multilingual blog like I do, so you’ll need to manually take care of couple of things.

  1. In your old blog Dashboard select Tools → Export → Choose what to export → All content → Press Download Export File. It will write an XML file and save it to your default download location (on your computer).
  2. In your new blog select Tools → Import → WordPress.
  3. This point it will ask you to install the WordPress import plugin. If your WP configuration for some reason does not support plugin installations via menus, then download the zipped plugin and decompress it to [your-blog-root]/wp-content/plugins/wordpress-importer.
  4. Choose your XML export file and choose “Upload file and import”.
  5. Now you may mark the posts to any author you have in the new blog.
  6. Tick “Download and import file attachments” so that all images and other attachments you have in the posts will be included.
  7. Select language from the drop-down. If you have a multilingual blog just select “English”.
  8. Press “Submit” and your (almost) done.
However, this approach has a problem:
  1. In multilingual blogs, the import will assign all posts to the default language you chose upon importing. You may now manually change the language of individual posts. Just select the post → Select the language from “Language of this” drop-down. Remember to link it to the other language version(s) from “This is translation of” drop-down. It will mess up the categories unfortunately. At first the categories seem to be correct but after you change the language of the post, it will be listed under “Uncategorized”. It will also lose the tags. So you’ll need to recreate the categories and tags for you other languages manually and link them to the posts.

Database Export/Import

I found it easier and faster to get an SQL dump of my old database, modify it slightly and import it to the new database. Here’s how to do it:

  1. Export the tables and data from the old database. You may use any method but I prefer phpMyAdmin. From the main view, select your database from the left and then “Export”. My version 3.4.4 has two export methods: Quick and Custom. I chose custom because I wanted to erase my new database tables before inserting data because that way it would be identical to the old one (for example users and sample posts would be erased). So I ticked “Add DROP TABLE/VIEW/PROCEDURE/FUNCTION/EVENT statement”. Then press “Go” and it will save the SQL dump file to your computer.
  2. Unfortunately there are couple of hard-coded values in the dump that refer your old blog that need to be changed. Open the SQL file in an editor and run a replace command. You should find all occurrences of your old blog URL and replace those with your new one. Then search for “siteurl” to find a row like “(1, 0, ‘siteurl’, ‘http://blog.arinium.fi’, ‘yes’),”. Make sure that the siteurl value is correct. I had a numerical IP there that was wrong.
  3. Import the SQL file into your new database. I used phpMyAdmin. From the main view, select your database from the left and then “Import”. Choose file and press “Go” and you’re done.
Also, you need to manually copy the uploads directory ([your-blog-root]/wp-content/uploads) to the new location.

Leave a Reply