Get Custom Post Type Post’s Count
- Article
- Comment
Get Custom Post type posts count. This is a small snippet which will give you the count of your custom post type. Sometimes we need to show some count of published posts on a custom post type. The following snippet will help you to get it.
$posts = get_posts('post_type=job'); $count = count($posts); echo $count;
Also, you can get the count based on Post Status, The following snippet will get you the drafted post counts,
$posts = get_posts('post_type=job&post_status=draft'); $count = count($posts); echo $count;
Likewise, you can get the count of publish, pending, trashed post counts. also you can get the posts based on its author. You can get Custom Post type count based on Author. The following snippet will help you to get it.
$posts = get_posts('post_type=job&post_author=1'); $count = count($posts); echo $count;
likewise, you can get custom post type count.