Make WordPress Core

Changeset 3887


Ignore:
Timestamp:
06/19/2006 05:17:52 PM (19 years ago)
Author:
ryan
Message:

wp_update_comment_count() from MarkJaquith. fixes #2836

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/comment.php

    r3851 r3887  
    253253    $post_id = $comment->comment_post_ID;
    254254    if ( $post_id && $comment->comment_approved == 1 )
    255         $wpdb->query( "UPDATE $wpdb->posts SET comment_count = comment_count - 1 WHERE ID = '$post_id'" );
     255        wp_update_comment_count($post_id);
    256256
    257257    do_action('wp_set_comment_status', $comment_id, 'delete');
     
    301301    $id = $wpdb->insert_id;
    302302
    303     if ( $comment_approved == 1) {
    304         $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND comment_approved = '1'");
    305         $wpdb->query( "UPDATE $wpdb->posts SET comment_count = $count WHERE ID = '$comment_post_ID'" );
    306     }
     303    if ( $comment_approved == 1)
     304        wp_update_comment_count($comment_post_ID);
     305
    307306    return $id;
    308307}
     
    420419    $rval = $wpdb->rows_affected;
    421420
    422     $c = $wpdb->get_row( "SELECT count(*) as c FROM {$wpdb->comments} WHERE comment_post_ID = '$comment_post_ID' AND comment_approved = '1'" );
    423     if( is_object( $c ) )
    424         $wpdb->query( "UPDATE $wpdb->posts SET comment_count = '$c->c' WHERE ID = '$comment_post_ID'" );
     421    wp_update_comment_count($comment_post_ID);
    425422
    426423    do_action('edit_comment', $comment_ID);
    427424
    428425    return $rval;
     426}
     427
     428function wp_update_comment_count($post_id) {
     429    global $wpdb, $comment_count_cache;
     430    $post_id = (int) $post_id;
     431    if ( !$post_id )
     432        return false;
     433    $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1'");
     434    $wpdb->query("UPDATE $wpdb->posts SET comment_count = $count WHERE ID = '$post_id'");
     435    $comment_count_cache[$post_id] = $count;
     436    return true;
    429437}
    430438
Note: See TracChangeset for help on using the changeset viewer.