I recently created a new WP site with some of the same content from my old WP site.

Is there a way to migrate comments from my old database to me new database? i tried importing old the wp_comments table into my new db via phpmysql. They did import and appeared in my wp admin, but they weren't associated with the correct posts and categories. Looking at the .sql file I'm guessing that this didn't work because the old comments all have different comment_post_IDs from my new db.

Is there a way around this or another way to migrate the old comments?

2 Answers 2


You could export all of the posts from your old site, including comments. Then, import them into your new site and delete the posts you don't want. This will preserve all of the links between posts and comments.

  • yes, I thought about this but i'm not able to export from wp because the old site is gone:( i only have the db.
    – roybatty
    Commented Apr 25, 2012 at 14:29
  • @roybatty If you have the database, you have the posts, you should be able to import it all.
    – mor7ifer
    Commented Apr 29, 2012 at 22:46
  • @m0r7if3r - thanks, but the new site has a mix of old and new content, so if i import the old db in phpmysql, won't I lose my newer content?
    – roybatty
    Commented May 4, 2012 at 20:40
  • @roybatty It depends how you do it. I'm not sure what phpmysql is, but with most database administration tools, you have a decent amount of control over how the data is imported, so you could import to a new set of tables and then merge them into the existing tables or, if you have the time and need the control, copy the rows over one at a time...just make sure you don't overwrite anything, make sure the meta stays associated if necessary, and make sure unique rows stay unique (permalinks, post_ids)
    – mor7ifer
    Commented May 4, 2012 at 20:44

I see at least 3 solutions:

  • install old version of wordpress on a development machine, import your database and change settings from wp-config to use the database you imported; Then export anything you want;

  • If you saved the old ids in `wp_postmeta you can make a script that do this:

a) select comment_post_ID from wp_comments;

b) select ID from wp_posts where old_id = id selected at a);

c) update wp_comments and set comment_post_ID = id selected at b); I think it is possible to do this from a single MySQL query;

If there aren't too many posts, you could manually update wp_comments (import your database and using PhpMyAdmin, see what is the old id of every post, see what is the new id in your newly wordpress install and run this query UPDATE wp_comments SET comment_post_ID = new_id WHERE comment_post_ID = old_id;)


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.