Definition:
function get_comment_count( $post_id = 0 ) {}
The amount of comments in a post or total comments.
A lot like wp_count_comments(), in that they both return comment stats (albeit with different types). The wp_count_comments() actual caches, but this function does not.
Parameters
- int $post_id: Optional. Comment amount in post if > 0, else total comments blog wide.
Return values
returns:The amount of spam, approved, awaiting moderation, and total comments.
Source code
function get_comment_count( $post_id = 0 ) {
global $wpdb;
$post_id = (int) $post_id;
$where = '';
if ( $post_id > 0 ) {
$where = $wpdb->prepare("WHERE comment_post_ID = %d", $post_id);
}
$totals = (array) $wpdb->get_results("
SELECT comment_approved, COUNT( * ) AS total
FROM {$wpdb->comments}
1308

February 12, 2011 


Trackbacks/Pingbacks
[…] actually worked pretty well except that it turns out that get_comment_count (and a lot of wordpress comment functionality) counts trackbacks and pingbacks towards comment […]