This code I have is working but I am not sure if it is the right way to do this. Basically when a user adds a record to a custom post type it goes straight to pending and needs an admin to publish it. I want the admin user to know their are records for them to approve by showing a red badge with a number in it, the same as when a plugin needs an update.

As mentioned, this works but maybe there is a better, more wordpress way to do it than running a custom SQL query?

add_action( 'admin_menu', 'add_user_menu_bubble' );

function add_user_menu_bubble() {
   global $wpdb;
   global $menu;

   $memo_count = $wpdb->get_var(" SELECT COUNT(*) FROM $wpdb->posts WHERE `post_status` = 'pending' AND `post_type` = 'memo'");

  if ( $memo_count ) {

    foreach ( $menu as $key => $value ) {

      if ( $menu[$key][2] == 'edit.php?post_type=memo' ) {

        $menu[$key][0] .= ' <span class="update-plugins">' . $memo_count . '</span>';


1 Answer 1


There's indeed a WordPress function for counting posts: wp_count_posts(). So you can do something like:

$memo_count = wp_count_posts( 'memo' )->pending;
  • 1
    That seems much simpler, thanks! Haven't tried it yet but will mark answer as accepted as I am assuming it is going to work May 22, 2020 at 15:31
  • Thanks so much and yes, I'm pretty sure it will work. :)
    – Sally CJ
    May 22, 2020 at 23:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.