2

This question already has an answer here:

I have added a custom post type called: "Partners", what I want is that when a new one is created, a notification appears in the sidebar of Wordpress.

For example:

enter image description here

regards!

marked as duplicate by Nathan Johnson, Jacob Peattie, Rick Hellewell, rudtek, Christine Cooper Mar 5 at 15:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • What have you tried so far? Where exactly are you stuck? – leymannx Feb 27 at 23:34
2

It is shockingly simple: you have to dyamically set the admin page title, adding a specific markup:

<span class='awaiting-mod count-3'>
  <span class='pending-count'>3</span>
</span>

So for example if you want to show the number of custom posts you have to do something like this when declaring the options page:

$notif_count = wp_count_posts('my_post_type'); //insert your post type
add_menu_page("My Page Title", 
              "My Page Title <span class='awaiting-mod count-$notif_count'><span class='pending-count'>$notif_count</span></span>", 
              'administrator',
              'my_slug', 
              'my_handler_function'
);

Notice the php variable $notif_count inside the second parameter of add_menu_page.

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