Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

thanks!

share|improve this question
add comment

2 Answers

I see at least 3 solutions:

  • install old version of wordpress on a development machine, import your 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;
share|improve this answer
    
thanks! i'm sure one of these will work for me. –  roybatty Apr 25 '12 at 20:44
add comment

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.

share|improve this answer
    
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 Apr 25 '12 at 14:29
    
@roybatty If you have the database, you have the posts, you should be able to import it all. –  m0r7if3r Apr 29 '12 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 May 4 '12 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) –  m0r7if3r May 4 '12 at 20:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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