migrate comments from old database to new database

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.

Read More

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

Related posts

Leave a Reply

2 comments

  1. 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.

  2. 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;)