Show Pending Post Count WordPress Admin Area

I will explain below how to show pending post count wordpress admin panel for default post type and custom post type. The following code will show the number of pending posts in the WordPress admin panel, you just need to add this code to the function.php file. You can add it to the $types array if you want to show the count number of pending posts in custom post type.

 

You can change the $status if you want to show draft count or etc. instead of pending posts.

 

function show_pending_number($menu) {
    $types = array("post", "car", "product");
    $status = "pending";
    foreach($types as $type) {
        $num_posts = wp_count_posts($type, 'readable');
        $pending_count = 0;
        if (!empty($num_posts->$status)) $pending_count = $num_posts->$status;
 
        if ($type == 'post') {
            $menu_str = 'edit.php';
        } else {
            $menu_str = 'edit.php?post_type=' . $type;
        }
 
        foreach( $menu as $menu_key => $menu_data ) {
            if( $menu_str != $menu_data[2] )
                continue;
            $menu[$menu_key][0] .= " <span class='update-plugins count-$pending_count'><span class='plugin-count'>"
                . number_format_i18n($pending_count)
                . '</span></span>';
        }
    }
    return $menu;
}
add_filter('add_menu_classes', 'show_pending_number');

4 Comments

  • Brian Turner


    This is a great article and helped a lot, can this also be done for pending users or pending events from Events Calendar?

    reply
  • Tibow


    Perfect solution !
    Thank you very much.
    Just had to change line 2 with the slug of my Custom Post Type (I work with CPT UI).

    reply

Leave a Reply

Your email address will not be published. Required fields are marked *