WordPress Help Articles

Total Posts by Type

Total Posts by Type

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.
Screenshot 20240428 160849

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');

Via Webs Offers WordPress Hosting & Maintenance Services for Those That Prefer to Focus on Something Other Than the Technical Aspects

Our rollover development time lets you save unused hours for future assistance. Stay updated and optimized, with the flexibility to invest in new functionality.

Article Categories

Dive in to something specific you are wanting to learn more about.

Let's Get Started!