Try this code:
function postsCount($meta_value) {
$args = array(
'numberposts' => -1,
'post_type' => 'custom_post_type', // set you custom post type
'meta_key' => 'project_select',
'meta_value' => $meta_value,
);
$my_posts = get_posts( $args );
$postsCount = count($my_posts);
return $postsCount;
}
if ( is_user_logged_in() ) {
echo postsCount('Draft');
echo postsCount('Completed');
}
or if you want to get all counts by less code, try this:
function postsCount() {
if ( !is_user_logged_in() ) {
return;
}
$meta_value_array = array( 'Draft', 'Open', 'Pending', 'Closed', 'Completed');
$postsCount="<ul>";
foreach ($meta_value_array as $meta_value) {
$args = array(
'numberposts' => -1,
'post_type' => 'custom_post_type', // set you custom post type
'meta_key' => 'project_select',
'meta_value' => $meta_value,
);
$my_posts = get_posts( $args );
$postsCount = count($my_posts);
$postsCount .= '<li>' .$meta_value. ' ' .$postsCount. '</li>';
}
$postsCount .= '</ul>';
return $postsCount;
}
echo postsCount();