wp_count_posts()
Is a type of specified article number of the article wordpress function by wp_count_posts()
function can count the number of articles of all types, such as post, page or custom post types post_type the like, may also be calculated to specify the state of the article, such as have been published, timed release, draft, pending, proprietary and so on.
Code structure:
1 |
<?php wp_count_posts('type', 'readable'); ?> |
Parameter Description
type - (character) optional, specifies the type of article (post_type), such as post, page or other custom post types, default post.
perm - (character) optional, this parameter can be counted in the privacy article states the article states, the use of "readable" and require users to log in, the default is empty.
return value
wp_count_posts()
The return value is an array
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Object the stdClass ( [publish] => // published. 11 [future] => 0 // timed release [draft] => 0 // Drafts [pending] => 0 // Unexamined [private] => 0 // private [trash] => 0 // trash [auto-draft] => 34 // automatic draft [inherit] => 0 // revision [-Request Pending] => 0 [Confirmed-Request] => 0 [ failed-Request] => 0 [Request-Completed] => 0 ) |
Example:
1, to obtain the number of published articles
1 2 3 4 5 |
<?php $count = wp_count_posts(); $getCount = $count->publish; echo $getCount; ?> |
2, to obtain the number of pages published
1 2 3 4 5 |
<?php $count = wp_count_posts('page'); $getCount = $count->publish; echo $getCount; ?> |