WordPress获取文章数量函数:wp_count_posts

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;
}

扩展阅读

wp_count_posts()函数位于:wp-includes/post.php

相关函数:

阿里云