Moving several posts from one blog to another
Thanks for visiting! If you're new here, you may want to subscribe to my RSS feed. My blog posts useful tips, ideas, tutorials and guides for WordPress bloggers - and articles about the life on the Canadian Prairies. If you are familiar with RSS readers, just add my feeds to your reader! You can also receive updates by email if you submit your email address in the box on the right.
I decided to move over here all my WP related posts from my “cross-cultural” blog, so the task was to extract (export) a few posts and their comments and to insert/import them into the database of this blog.
This post is a follow-up to my question posted in the WP forum.
As I was advised I used the phpMyAdmin offered by my host to perform this operation. Actually it turned out to be easier than expected. Here are the steps I have followed:
- Being in the proper database click on the wp_posts table name in the left panel (your tables might have a different prefix, this is just an example!)
- In the next panel click Browse on the top
- Select the the checkbox at the beginning of the rows that you want to export (for the sake of simplicity I’ll describe it here as exporting 1 single post=row)
- At the bottom of the rows where it says “With selected” - select “Export”
- On the next panel deselect Structure; leave selected Data, and check Save as file, then GO
- You will get a prefix_posts.sql file
- Open the file in your favourite text editor (definitely not MS Word); I used Notepad++
- Using Search/Replace change the
wp_part everywhere totarget_- depending on the prefix of the tables where you want to move the post - If you move the post to a new, empty database, you are ready to go. However if the target blog has already posts in its database, you have some more work to do:
- — check in the database what is the ID# of your last post in the target blog
- — Go back to the .sql file and take a look at the first line below
Dumping data for table.... It should be something like:
INSERT INTO `target_posts` VALUES (34, 1, '2005-03-31 03:13:10', ...
- — That very first number after the VALUE is the post ID#. Change it to your last post ID#+1, i.e. if the last post in your target blog has ID# 53, make it 54. Save the file.
Warning! You can chose any number, even 1,000 - but be aware that your next post made in the usual way from the admin Write Post panel will have 1001 as ID# in this case!
- Now go the the DB of the target blog, and select the
target_poststable - From the menu at the top select SQL
- On the next page select Location of the textfile: Browse and find the changed and saved .sql file on your computer; click Open and, when the path is displayed in the field, click GO
- If you are lucky, phpMyAdmin will report a successful action. The post is in your new/target blog. If you are concerned about the order where it appears, you can simply go to your blog admin panel and change the time stamp.
- Possible problems. If you are importing from a DB that was created by earlier WP versions, you may encounter an
"EROOR #1136 - Column count doesn't match value count at row 1". I got this error due to the two columns in the posts table: ‘post_lat’ and ‘post_lon’ that were there for the geo-location in WP 1.2 and earlier versions (see my post in the forum) - What I did: Checked the .sql file and found the two
'NULL', 'NULL'values after the text portion of the post (it was NULL since I’ve never used that feature) and simply deleted them. Now the number of columns was the same, and the import successful. - Another issue and warning. Be aware that some plugins create their own table in the WP database and this can cause the same
Erroras above. Check and compare the two databases and if there is any column created by a plugin, you have two choices:- — install the very same plugin into the DB that is missing it
- — delete the values referring to that column from the the source .sql file
- When you are done just do the import (SQL) query
With comments the procedure is very similar. For the post moved above I checked “on the surface” and saw there were 7 comments. Knowing that the post ID# used to be 34 I checked the wp_comments table in Browse mode to find the comments attached to that post. Checked all the 7 rows and exported them.
Next, opened the wp_comments.sql file in the text editor and
- changed the table prefix (see above)
- changed the post ID in the comments
For this latter you have to look at the .sql file and you can see for every comment exported there is a line starting like:
INSERT INTO `target_comments` VALUES (69, 37, 'Moshu',...etc. INSERT INTO `target_comments` VALUES (71, 37, 'John Doe',...etc.
Search/Replace “37″ with the post’s new ID# - which in my case was 54, see above. The first number is the comment’s own ID#.
If done, import it via the SQL query as we did with the post.
Warning: There might be error messages if the comment ID# is already in use. Just go back to editing, change the number to something that probably doesn’t exist, and try again the query.
I am sure there might be some other way to do this, especially if you are “fluent” in MySQL commands, but for those less skilled it can be helpful.









sorry i am not clear please explain me clearly.
for exmple :
If i have two databases which are in two differnt domains and the tables are also the same in both the domains and also the data in the tables may be same.some data may be differnt ? how to do in such cases please help me …..
This will definetly help me if/when I decide to move. Thanks
Thanks very much for taking the time to post the tips and “how-to’s”. There are few sites with as much concise, useful WordPress info. Those of us who are learning as we go find it invaluable.
I’ve used your page twice now when consolidating multiple blogs. Very useful. Perhaps these instructions should be made available in the WordPress Codex???
Hi moshu, as I said on the forum, thanks for the handy guide. Sadly I saw it after I posted a similar yet somewhat less comprehensive howto on my missus blog.
Thank you so much for the tutorial! It took several hours and a lot of concentration, but thanks to you I was able to move some posts that I wanted to keep, but which no longer fit in with the direction of my site. Please submit this to the Codex, it was a big help!
Thank you so bloody much!!!
I had made two backups of my blog, but when it came to the cruch they just didn’t seem to work .. I kept getting errors trying to install them.
But thanks to this I was able to pick out the posts and comments and put them in.
THANKS!!!
I have 2 blogs, domain1.com with many catagories and comments, and domain2.com with one catagory and no comments. I want to have 1 of domain1.com’s catagories be domain2.com’s 1 catagory blog.
Is this kinda the same? How would I do this?
Welp!!
Thank you for an excellent explanation that helped me a great deal when I needed to fill my development blog with material from the original blog (swedish foodblog).
I’m glad I came accross this site as it was the exact info I was looking for.
You have saved me much time and effort.
Wonderful. Thank you. The last time I changed databases I “had” to hand transfer each file — like cut and paste and backdate. So I appreciate your smartness.
And for your records, my old database was using wordpress 2.0, the new one 2.0.5 — no problems there. I just had to add a plug-in and change the ID of a couple static pages.
Wish I had found this post a few weeks ago when I was converting a blog to a new one.
Well it is bookmarked now.
Hi this tutorial was very helpful. Everything worked out good but for some reason my comments are only showing up in the admin login area but not on my blog site. my blogs that i imported say i have (#of comments) but when i click to read them on my site they don’t show up. =[
Did you try to switch to the default or classic theme? Sometimes, problems like this could be theme-related. Other than that I don’t know what to say - since I don’t have access to your site…