Home > Computing > Fixing Comment Counts in WordPress

Fixing Comment Counts in WordPress

September 27th, 2007 beezly Leave a comment Go to comments

As I’ve just migrated to using WordPress for my blog, I thought I’d add some useful information in my first post.

WordPress caches comment counts for each individual article in wp_posts.comment_count. If for some reason these cached values don’t match up to the real comment counts per article, you can fix this using the following SQL. This applies to WordPress 2.3. I don’t know if it will work for anything else.

UPDATE wp_posts
  SET comment_count = (
   SELECT COUNT(*)
     FROM wp_comments
     WHERE wp_posts.ID=wp_comments.comment_post_id
     GROUP BY wp_comments.comment_post_id
   );
Categories: Computing Tags: ,
  1. No comments yet.
  1. No trackbacks yet.