How to Use
Download > Install > Activate. Click on the new admin sidebar icon labeled “Post Type Counts”.
Example
Instantly view the total posts counts for each post type and the overall sum.
Source
This code can be pasted into the functions.php file of your child theme or, download and install the plugin for simple code activation.
function viawebs_post_types_counts() {
$post_types = get_post_types(['public' => true], 'objects');
$total_count = 0;
$output = '';
foreach ($post_types as $post_type) {
$count = wp_count_posts($post_type->name)->publish;
$total_count += $count;
$output .= "Total " . $post_type->labels->name . ": " . $count . "<br>";
}
$output .= "<br><strong>Total Counts Of All Post Types: " . $total_count . "</strong>";
return $output;
}
function viawebs_add_post_count_admin_page() {
add_menu_page(
'Post Type Counts',
'Post Type Counts',
'manage_options',
'vw-post-type-counts',
'viawebs_display_admin_page'
);
}
function viawebs_display_admin_page() {
echo '<div class="wrap"><h1>Post Type Counts</h1>';
echo viawebs_post_types_counts();
echo '</div>';
}
add_action('admin_menu', 'viawebs_add_post_count_admin_page');