Codex

Template Tags/wp count posts

Contents

Description

First available with WordPress Version 2.5, this template tag returns the count of the rows in wp_posts that meet the post_type and post_status designated.

Usage

 <?php wp_count_posts('type''status'); ?> 

Examples

Default Usage

The default usage returns a count of the posts that are published.

<?php $published_posts=wp_count_posts(); ?>

Count drafts

Return the count of post drafts.

<?php $draft_posts=wp_count_posts('post','draft'); ?>

Count pages

Return the count the number of published pages

<?php $published_pages=wp_count_posts('page','publish'); ?>

Parameters

type 
(string) Type of row in wp_posts to count where type is equal to post_type. Defaults to post
status 
(string) Status of row in wp_posts to count where status is equal to post_status. Default to publish

Related

the_ID, the_title, the_title_attribute, single_post_title, the_title_rss, the_content, the_content_rss, the_excerpt, the_excerpt_rss, previous_post_link, next_post_link, posts_nav_link, the_meta

How to pass parameters to tags with PHP function-style parameters

Go to Template Tag index

This page is marked as incomplete. You can help Codex by expanding it.