WordPress获取文章数量函数:wp_count_posts

文 / @WordPress主题

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

相关函数:

  • current_user_can()
  • wp_cache_get()
  • wp_cache_set()
  • is_user_logged_in()
添加UTHEME为好友
扫码添加UTHEME微信为好友
· 分享WordPress相关技术文章,主题上新与优惠动态早知道。
· 微信端最大WordPress社群,限时免费入群。