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.


  • 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}



  1. Hide “0 Comments” link in Wordpress when using the Disqus Plugin | BlogFox - June 8, 2011

    […] 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 […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: