Title: get_comment_count
Published: April 25, 2014
Last modified: August 20, 2026

---

# get_comment_count( int $post_id ): int[]

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_comment_count/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_comment_count/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_comment_count/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_comment_count/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_comment_count/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/get_comment_count/?output_format=md#wp--skip-link--target)

Retrieves the total comment counts for the whole site or a single post.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_comment_count/?output_format=md#parameters)󠁿

 `$post_id`intoptional

Restrict the comment counts to the given post. Default 0, which indicates that comment
counts for the whole site will be retrieved.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_comment_count/?output_format=md#return)󠁿

 int[] The number of comments keyed by their status.

 * `approved` int
 * The number of approved comments.
 * `awaiting_moderation` int
 * The number of comments awaiting moderation (a.k.a. pending).
 * `spam` int
 * The number of spam comments.
 * `trash` int
 * The number of trashed comments.
 * `post-trashed` int
 * The number of comments for posts that are in the trash.
 * `total_comments` int
 * The total number of non-trashed comments, including spam.
 * `all` int
 * The total number of pending or approved comments.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_comment_count/?output_format=md#source)󠁿

    ```php
    function get_comment_count( $post_id = 0 ) {
    	$post_id = (int) $post_id;

    	$comment_count = array(
    		'approved'            => 0,
    		'awaiting_moderation' => 0,
    		'spam'                => 0,
    		'trash'               => 0,
    		'post-trashed'        => 0,
    		'total_comments'      => 0,
    		'all'                 => 0,
    	);

    	$args = array(
    		'count'                     => true,
    		'update_comment_meta_cache' => false,
    		'orderby'                   => 'none',
    	);
    	if ( $post_id > 0 ) {
    		$args['post_id'] = $post_id;
    	}
    	$mapping       = array(
    		'approved'            => 'approve',
    		'awaiting_moderation' => 'hold',
    		'spam'                => 'spam',
    		'trash'               => 'trash',
    		'post-trashed'        => 'post-trashed',
    	);
    	$comment_count = array();
    	foreach ( $mapping as $key => $value ) {
    		$comment_count[ $key ] = get_comments( array_merge( $args, array( 'status' => $value ) ) );
    	}

    	$comment_count['all']            = $comment_count['approved'] + $comment_count['awaiting_moderation'];
    	$comment_count['total_comments'] = $comment_count['all'] + $comment_count['spam'];

    	return array_map( 'intval', $comment_count );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/comment.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/comment.php#L463)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/comment.php#L463-L500)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_comment_count/?output_format=md#related)󠁿

| Uses | Description | 
| [get_comments()](https://developer.wordpress.org/reference/functions/get_comments/)`wp-includes/comment.php` |

Retrieves a list of comments.

  |

| Used by | Description | 
| [wp_count_comments()](https://developer.wordpress.org/reference/functions/wp_count_comments/)`wp-includes/comment.php` |

Retrieves the total comment counts for the whole site or a single post.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_comment_count/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_comment_count%2F)
before being able to contribute a note or feedback.