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

Use WordPress’s built-in wp_count_posts() function to get a post count without loading every post. For a public-facing total, display only the published count and format it for the site’s locale:

$count = wp_count_posts();
echo esc_html( number_format_i18n( $count->publish ) );

This default call counts the standard post type. The example formats the number for the current locale and escapes it before output in HTML.

Show the published post count in a theme

Place the code where the number should appear in a theme template, such as beside a short label:

<p>Published posts: <?php
$count = wp_count_posts();
echo esc_html( number_format_i18n( $count->publish ) );
?></p>

The count can be output directly in a template; you do not need to retrieve each post through the Loop just to count them. WordPress documents wp_count_posts() as an efficient way to count items by post type and status. By comparison, get_posts() retrieves matching post objects or IDs and defaults to returning five results, so it is not the appropriate tool for counting a whole collection.

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

Choose the post type you want to count

wp_count_posts() defaults to the standard post type; it does not mean every kind of content on the site. Pass a registered type’s slug to count another type:

$pages = wp_count_posts( 'page' );
echo esc_html( number_format_i18n( $pages->publish ) );

The same pattern works with a registered custom post type, using that type’s actual slug in place of page. The function returns an empty object if the requested post type does not exist, so confirm the slug is registered on the site.

Understand what the returned count includes

The function returns an object with counts separated by status. Use its publish property when the intended number is content visitors can ordinarily see. Do not add all the status counts together unless you deliberately want to include other categories such as drafts, private posts, or trashed posts.

For permission-aware handling of private posts, the function accepts readable as its second parameter. WordPress’s post list table uses wp_count_posts( $post_type, 'readable' ) and applies status visibility rules when it calculates its total. A public page should not expose a count of private or draft content unless that is an intentional choice.

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

Counts are cached, and the wp_count_posts filter can alter the returned object. Custom post type configuration and site-specific filters may therefore affect the number displayed.

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

See published counts in the WordPress dashboard

If you only need to check standard post and page totals as an administrator, use the existing At a Glance dashboard widget. It already calls wp_count_posts() and displays published counts, so custom code is unnecessary for that purpose.

For a registered custom post type, WordPress provides the dashboard_glance_items hook for extending the widget. Its documentation example is user-contributed; check that it fits the conventions and configuration of your site before adopting it.

When to use a different approach

  • Public total of standard posts: Call wp_count_posts() with no type argument and display ->publish.
  • Published pages or custom content: Pass the registered type slug, then display ->publish.
  • Administrator view of built-in totals: Check the At a Glance widget.
  • Total across statuses: Decide which statuses and permissions belong in that figure before adding counts; it is not automatically the same as a public post total.

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.

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