Moving comments in WordPress

In MySQL, first move the comment:

UPDATE wp_comments SET comment_post_ID = P_TO_ID WHERE comment_ID = C_ID;

P_TO_ID is the ID of the post you are moving it to. C_ID is the ID of the comment you are moving. You can find both of these IDs easily from the dashboard.

Then correct the comment counts for the posts:

UPDATE wp_posts SET comment_count = (SELECT count(*) FROM wp_comments WHERE comment_post_id = id AND comment_approved = 1)
WHERE comment_count != (SELECT count(*) FROM wp_comments WHERE comment_post_id = id AND comment_approved = 1);

The second line in this query is not strictly necessary but it lets you know how many posts were affected.

Tags: ,

Leave a Reply