Is it cool to be a total station statistic? Long-term blog fewer and less, why not give yourself a statistic to see how much they have worked on this blog, not only to give themselves to tourists, wp_count_posts is used in WordPress to count the number of articles in the function, You can count all types of articles (post) and Pages (page).
Describe
Wp_count_posts is a function to count the number of articles in WordPress, and you can count all types of posts (post) and Pages (page).
Use
Get the article quantity
$postcount = Wp_count_posts ();
Get the number of pages
$pagecount = wp_count_posts (' page ');
return value
the use is roughly the above two forms,
The function is used primarily on the return value,
Both of these forms return an object,
As follows: May not be the same value, but the structure is the same
Object (StdClass) #296 (8) {
//Published
["Publish"]=>string (1) "7"
//Scheduled publication
["Future"]=>int (0)
//Drafts
["Draft"]=>int (0)
//is being edited? (To be verified)
["Pending"]=>int (0)
//Privacy
["Private"]=>int (0)
//Trash bin
["Trash"]=>int (0)
//Automatic drafts
["Auto-draft"]=>int (0)
//This does not know, also did not study
["Inherit"]=>int (0)
}
Default usage
The default usage returns the count of published articles. This is an object that you can use Var_dump () to debug output in your content.
<?php
$count _posts = wp_count_posts ();
? >
Get the count of published status articles
To get the status type for a published article, you should first call the Wp_count_posts () function and then view the Publish property.
<?php
$count _posts = wp_count_posts ();
$published _posts = $count _posts->publish;
? >
If you use PHP5 and just want to get an article status, you can use the following more convenient method. This code cannot be run in PHP4, so if you want to maintain background compatibility, you should select the code above.
<?php
$published _posts = wp_count_posts ()->publish;
? >
Draft count
The calculation of the draft quantity method is consistent with the Get Publish status Count method.
<?php
$count _posts = wp_count_posts ();
$draft _posts = $count _posts->draft;
? >
Page Count
The method for calculating the number of page types is the same as for a calculated article, and the first argument is also required. Finding the number of pages in a state is the same as looking for a log method in that state.
<?php
$count _pages = wp_count_posts (' page ');
? >
Other usage
Wp_count_posts () finds the number of log types in the log state, including attachments and any log types that will be added, or through a plug-in or some core team in WordPress.
Parameters
Type
(character) wp_posts the type of row that is used to verify which type corresponds to the Post_type. The default post.
Perm
(character) This parameter can be used to calculate the status of the private article in the article State, using ' readable ' and require the user to log in. The default is empty string.