wp_update_comment_count hook from mdawaffe. fixes #4740

git-svn-id: http://svn.automattic.com/wordpress/trunk@5869 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-08-14 03:08:44 +00:00
parent 2ae70d7c72
commit ddc05f60ea
1 changed files with 10 additions and 6 deletions

View File

@ -500,17 +500,21 @@ function wp_update_comment_count($post_id) {
$post_id = (int) $post_id;
if ( !$post_id )
return false;
$count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1'");
$wpdb->query("UPDATE $wpdb->posts SET comment_count = $count WHERE ID = '$post_id'");
$comment_count_cache[$post_id] = $count;
if ( !$post = get_post($post_id) )
return false;
$old = (int) $post->comment_count;
$new = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1'");
$wpdb->query("UPDATE $wpdb->posts SET comment_count = '$new' WHERE ID = '$post_id'");
$comment_count_cache[$post_id] = $new;
$post = get_post($post_id);
if ( 'page' == $post->post_type )
clean_page_cache( $post_id );
else
clean_post_cache( $post_id );
do_action('edit_post', $post_id);
do_action('wp_update_comment_count', $post_id, $new, $old);
do_action('edit_post', $post_id, $post);
return true;
}
@ -816,4 +820,4 @@ function update_comment_cache($comments) {
wp_cache_add($comment->comment_ID, $comment, 'comment');
}
?>
?>