Following process will add pending post count in admin menu items..
You also can change as your need..
Edit the theme's `function.php` and add following line of code :-
First, add hook to admin menu
//Add hook to Admin Menu.
add_action('admin_menu', 'notification_count_in_admin_menu');
Now add function that will alter you menu with notification count.
function notification_count_in_admin_menu()
{
global $menu;
$post_types = array('post', 'page', 'your_cpt');
foreach ($post_types as $type)
{
$post_count = get_number_of_pending_post_by_type($type);
if(!empty($post_count))
{
foreach ( (array)$menu as $key => $parent_menu )
{
if ( $parent_menu[2] == 'edit.php?post_type='.$type )
{
$menu[$key][0] = $menu[$key][0]. ''.$post_count.'';
}
}
}
}
}
function get_number_of_pending_post_by_type($type)
{
global $wpdb;
return $wpdb->get_var( "SELECT COUNT(ID) as count FROM {$wpdb->post} WHERE `post_status`='pending' AND `post_type`='{$type}';" );
}
Have fun!
No comments:
Post a Comment