NB: Make sure you do a back up of your theme, files and database before attempting the tutorials
Intermediate
Last modified : Sep 06 2022
Estimated reading time : 1 minute, 15 seconds - 72 words
Share the post "Display the Number of Posts with Draft Status in Admin Menu"
This tutorial will show you how to add a new function in your WordPress admin which will display the number of posts and post-type with a Draft status.
This function will help WordPress admins to validate posts and post type pending verification with the Draft status.
To accomplish this, we will use the add_menu_classes filter.
Display the Number of Posts with Draft Status in Admin Menu
add_filter( 'add_menu_classes', 'viavideos_pending_number'); function viavideos_pending_number( $menu ) { // Changer par le nom de votre Post Type ou post $type = 'viavideos'; // Vous pouvez ici mettre un autre statut $status = 'draft'; // On fait le compte des Posts Ou Post Type $num_posts = wp_count_posts( $type, 'readable' ); // On part de 0 en statut draft et on fait le compte $pending_count = 0; if ( !empty($num_posts->$status) ) $pending_count = $num_posts->$status; // build string to match in $menu array if ($type == 'post') { $menu_str = 'edit.php'; // support custom post types } else { $menu_str = 'edit.php?post_type=' . $type; } // On affiche le resultat dans le menu admin concerné 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; }