我有一些类别,每个类别都有一些子类别。
例如:
Entertainment(slug = 'entertainment')
--- Movies
--- Drama
--- Sports我想检索entertainment及其子类别中所有帖子的数量计数
但是我得到的最大计数是10 everytime.When,总共有13篇文章,它的10篇文章,但是如果少于10篇文章,它的确切数量。它为13的8..but 10返回8
我的代码是
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;
}发布于 2017-10-03 07:58:38
尝试通过查询传递'posts_per_page'=>-1。
即
$post = new WP_Query( array('category_name' => $slug, 'posts_per_page'=>-1) );https://stackoverflow.com/questions/46539678
复制相似问题