Do you want to find and display total number of posts published on your WordPress site? Here’s the code.
Get the number of published posts using the $wpdb object, while making sure to exclude the post revisions and auto saved posts.
$agentwp_num = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND post_name NOT LIKE '%revision%' AND post_name NOT LIKE '%autosave%'" );
Now, the $agentwp_num
variable contains the total number of posts published on your WordPress blog, excluding the auto saved posts and post revisions.
It can be displayed anywhere in the template files with the code below,
if (0 < $agentwp_num) $agentwp_num = number_format($agentwp_num);
echo $agentwp_num.' posts published since we are online!';
echo $agentwp_num.' posts published since we are online!';