How to move WordPress comments using MySQL.
- July 13th, 2012
- Posted in Documentation
- Write comment
Used the following method to move comments in WordPress 3.
Key information needed:
Determine the post ID (comment_post_ID) for where the comment was made. You can determine this from the WordPress Dashboard. In this post, (http://jim-zimmerman.com/?p=781) 781 is the comment_post_ID.
Determine the post ID (comment_post_ID)for where the comment should go.
Determine the comment ID (comment_ID). There are many ways you could determine this, but you should probably choose something unique to the comment like the comment_author_email that you should be able to get from the comment.
Move the comment:
mysql> UPDATE wp_comments SET comment_post_id=”newcommentpostid” WHERE comment_post_ID=”oldcommentpostid” AND comment_author_email=”commentauthoremail“;
Determine the number of comments where the post has moved to:
mysql> SELECT COUNT(*) FROM wp_comments WHERE comment_post_id=”newcommentpostid“;
Determine the updated number of comments for the post where the comment was originally made:
mysql> SELECT COUNT(*) FROM wp_comments WHERE comment_post_id=”oldcommentpostid“;
Update the counts for each of the posts:
mysql> UPDATE wp_posts SET comment_count=”newcommentcountwhereadded” WHERE id=”newpostid“;
mysql> UPDATE wp_posts SET comment_count=”newcommentcountwhereremoved” WHERE id=”oldpostid“;
No comments yet.