function wp_count_posts( $type = 'post', $perm = '' ) {}

Count number of posts of a post type and is user has permissions to view.
This function provides an efficient method of finding the amount of post’s type a blog has. Another method is to count the amount of items in get_posts(), but that method has a lot of overhead with doing so. Therefore, when developing for 2.5+, use this function instead.


  • string $type: Optional. Post type to retrieve count
  • string $perm: Optional. ‘readable’ or empty.

Return values

returns:of posts for each status

Source code

function wp_count_posts( $type = 'post', $perm = '' ) {

	global $wpdb;

	$user = wp_get_current_user();

	$cache_key = $type;

	$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";


No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: