Much like how the Plugins or Comments menu items have these number notifications in a bubble for updates and unmoderated comments respectively, I’d like to use that bubble to display the number of CPTs which have a “Pending review” status. How to go about doing that?
I have found this thread, but not quite sure where to go from there.
That would be neat to have; as I need this feature on a site that uses user-generated content (custom post types). Whenever users submit a new CPT, its status is set to “Pending review”, and I want the site admins to quickly glance at the menu to see how many items need their attention.
EDIT: I now have this code:
// buuble notifications for custom posts with status pending
add_action( 'admin_menu', 'add_pending_bubble' );
function add_pending_bubble() {
global $menu;
$custom_post_count = wp_count_posts('custom-post-name');
$custom_post_pending_count = $custom_post_count->pending;
if ( $custom_post_pending_count ) {
foreach ( $menu as $key => $value ) {
if ( $menu[$key][2] == 'edit.php?post_type=custom-post-name' ) {
$menu[$key][0] .= ' <span class="update-plugins count-' . $custom_post_pending_count . '"><span class="plugin-count">' . $custom_post_pending_count . '</span></span>';
return;
}
}
}
}
…which does work, albeit a bit inconsistent. Sometimes displaying, sometimes not. Also, if I have multiple CPTs, how do I apply this code for each and every menu item of those CPTs? The above code will work with only one CPT.
I made this work iterating through a post types list, and pinpointing the correct
$menu
key for the post type using a secondary function (instead of manually iterating through the$menu
object).Function reference:
get_post_types
andwp_count_posts
.