Recently, I had to move to another domain and had to recreate all my MySQL tables on the enw server. I noticed that for some posts, the number of comments is doubled. Example – http://inversekarma.in/scraps/you-dont-mess-with-the-rajinikanth/.
In the above post, there’s only 4 comments, but the comment count shoes 8 comments. I am not sure it is not a theme-related issue, as this happens only for a few posts.
Can someone show me how to write a MySQL query to recount the comments for all posts? Or maybe a plugin?
Try this code:
WARNING: THIS IS JUST PSEUDOCODE!
Or you might want to try solution from this page (although it’s not the proper way as you will add another query for every post)
Seems to be a common problem. Try this plugin:
http://wordpress.org/extend/plugins/web-ninja-comment-count-fixer/
There’s a WordPress API just for that: wp_update_comment_count($post_id, $do_deferred). Granted, it operates on a single post, although it has a deferring mechanism to accumulate many of them and just update the count in one go.