Retrieve the amount of comments a post has.

Signature

get_comments_number( $post_id = 0 )
post_id
 (int|WP_Post) Optional. Post ID or WP_Post object. Default is global $post.
Default: 0

Return

(int) The number of comments a post has.

Source

function get_comments_number( $post_id = 0 ) {
	$post = get_post( $post_id );

	if ( ! $post ) {
		$count = 0;
	} else {
		$count = $post->comment_count;
		$post_id = $post->ID;
	}

	/**
	 * Filter the returned comment count for a post.
	 *
	 * @since 1.5.0
	 *
	 * @param int $count   Number of comments a post has.
	 * @param int $post_id Post ID.
	 */
	return apply_filters( 'get_comments_number', $count, $post_id );
}
WP Trac GitHub

Link here