I have some categories and each category have some subcategories.
For example :
Entertainment(slug = 'entertainment')
--- Movies
--- Drama
--- Sports
I want to retrieve the number count of all posts in entertainment
and its sub categories
But max count i am getting is 10 everytime.When there is total 13 posts its 10 but if less than 10 posts its exact number. it return 8 for 8..but 10 for 13
function PrinzPostCatCount( $slug ){
// category posts count
$args = array(
'posts_per_page' => -1,
'category_name' => $slug,
);
$post = new WP_Query( $args );
return (int) $post->post_count;
}
Try to pass 'posts_per_page'=>-1
with the query.
ie
$post = new WP_Query( array('category_name' => $slug, 'posts_per_page'=>-1) );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.