Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress: Count number of posts, exclude uncategorized

Using this code I can easily get the total number of posts:

$post_count = count_user_posts();
echo $post_count;

But I need the total to not include posts that are uncategorized.

like image 217
Miker Avatar asked Nov 11 '13 01:11

Miker


Video Answer


1 Answers

Use the following code and see the output:

$args = array('posts_per_page' => -1,'category' => '-1',);
$posts_array = get_posts( $args );
echo count($posts_array);

As default, id of uncategorized category is 1.

like image 192
StreetCoder Avatar answered Sep 19 '22 22:09

StreetCoder