Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To display the normal comment count for a post, use comments_number() for a ready-made label or get_comments_number() when you need the numeric value. That number comes from the post’s stored comment_count; it is not a live breakdown by comment status. If you need to count only approved comments—or include pending, spam, or trashed comments—use get_comment_count() and choose the relevant status key.

Choose what “accurate” means for your site

WordPress offers two different kinds of comment counts. The ordinary per-post count is the value stored in the post’s comment_count property. A status breakdown reports how many comments are approved, awaiting moderation, spam, or trash. Decide which number your label should represent before adding it to a theme.

  • Standard display count: Use comments_number() to print a zero, singular, or plural label, or get_comments_number() to retrieve the number.
  • Status-specific count: Use get_comment_count( $post_id ) and select a key such as approved or all.

Display the standard count in a theme

Print a zero, one, or plural label

In a template where the intended post is the global post, call comments_number():

<?php comments_number( 'No comments', '1 comment', '% comments' ); ?>

The function prints the appropriate text: the first argument for zero, the second for one, and the third for multiple comments. In the plural text, % is replaced with the locale-formatted number. WordPress also provides a filter that can alter this display text.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Retrieve a numeric value

Use get_comments_number() when your code needs the number for custom markup or logic. It accepts a post ID or a WP_Post object; if omitted, it uses the global post.

<?php
$count = get_comments_number( $post_id );
echo esc_html( number_format_i18n( (int) $count ) );
?>

Replace $post_id with the ID of the post you want to display. If your code is already running in the correct global post context, you can omit the argument. The function returns the post’s stored comment_count, returns zero if the post does not exist, and applies the get_comments_number filter. Escape the value for its output context; the example uses esc_html() for HTML text.

Count approved, pending, or other comment statuses

For a status-aware count, call get_comment_count() with the post ID:

<?php
$counts = get_comment_count( $post_id );
echo esc_html( number_format_i18n( $counts['approved'] ) );
?>

The documented result includes these keys:

  • approved: approved comments.
  • awaiting_moderation: comments awaiting moderation.
  • spam and trash: comments in those respective states.
  • post-trashed: comments associated with a trashed post.
  • all: approved comments plus comments awaiting moderation.
  • total_comments: all plus spam.

Choose a label that accurately describes the key. For example, label $counts['approved'] as “approved comments”; do not describe $counts['all'] as approved-only, because it also includes comments awaiting moderation.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Which WordPress function should you use?

Need Function What it provides
Print standard zero, one, or plural text comments_number() Outputs the display text directly.
Retrieve a post’s ordinary comment number get_comments_number() Returns the stored comment_count value and applies the get_comments_number filter.
Get formatted display text for custom markup get_comments_number_text() Handles singular and plural wording and locale formatting; applies the comments_number filter.
Inspect comment states for a post get_comment_count( $post_id ) Returns status-specific counts.
Read status totals that may be cached wp_count_comments( $post_id ) Returns an object of comment-status counts and may use cached results.

Troubleshoot a count that looks wrong

  1. Confirm the intended post. Outside the Loop or another global post context, pass the correct post ID or WP_Post object to the display function. An omitted argument may point to a different global post.
  2. Compare the stored display number with statuses. Check get_comments_number( $post_id ) against the relevant keys from get_comment_count( $post_id ). Confirm that both values answer the same question: for example, ordinary display count versus approved-only count.
  3. Check cached totals if you use them. wp_count_comments() may return cached status counts. Its reference points to get_comment_count() for live counts, making the latter a better check when investigating a suspected stale value.
  4. Inspect theme and plugin filters. WordPress documents filters for get_comments_number, comments_number, and wp_count_comments. A theme or plugin attached to one of them may change the returned count or displayed wording.

These checks help narrow down the mismatch; the APIs alone do not identify why a particular site’s count differs. Avoid editing database values as a first response: verify the post context, compare the stored count with the status breakdown, and check filters and caching.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

WordPress reference notes

These functions are documented in the WordPress Developer Resources Code Reference. The references list comments_number() as dating to WordPress 0.71, get_comments_number() to 1.5.0, get_comment_count() to 2.0.0, and wp_count_comments() to 2.5.0. The post parameter for comments_number() and get_comments_number_text() was added in WordPress 5.4.0. The references were accessed on September 30, 2026; consult them for current details and changelogs.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.