From e53912a4ddbf628e43417ce074d539012889aea7 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Tue, 22 Nov 2005 03:45:40 +0000 Subject: [PATCH] Instead of incrementing the current comment count, recount all comments to make sure we have a good count. Props Mark Jaquith. fixes #1920 git-svn-id: https://develop.svn.wordpress.org/trunk@3193 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/comment-functions.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/wp-includes/comment-functions.php b/wp-includes/comment-functions.php index 85f7ba1b23..5f52018c86 100644 --- a/wp-includes/comment-functions.php +++ b/wp-includes/comment-functions.php @@ -83,9 +83,10 @@ function wp_insert_comment($commentdata) { $id = $wpdb->insert_id; - if ( $comment_approved == 1) - $wpdb->query( "UPDATE $wpdb->posts SET comment_count = comment_count + 1 WHERE ID = '$comment_post_ID'" ); - + if ( $comment_approved == 1) { + $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND comment_approved = '1'"); + $wpdb->query( "UPDATE $wpdb->posts SET comment_count = $count WHERE ID = '$comment_post_ID'" ); + } return $id; }