From 24e23074456fb8341de76679147dbdcafe179b26 Mon Sep 17 00:00:00 2001 From: ryan 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: http://svn.automattic.com/wordpress/trunk@3193 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- 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; }