wordpress

如何获取分类文章数?

无评论

作者照片

By 霜天

WordPress函数wp_count_posts返回指定文章类型的文章数量,并且可以根据已登录用户的权限来返回数据,只返回该用户拥有读权限的文章数量。

wp_count_posts( string $type = 'post', string $perm = '' )

函数参数

$type

字符串,默认值:post

文章类型的名称

$perm

字符串,默认为空

如果指定值为readable,则只返回当前登录用户具有读权限的文章数量。

函数使用示例

$count_posts = wp_count_posts();if($count_posts) {    $published_posts = $count_posts->publish;}

发表评论