当前位置:首页 > 云计算 > 正文内容

WordPress获取文章数量函数:wp_count_posts

2022-05-31 08:14:52云计算7

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()

本网站文章仅供交流学习 ,不作为商用, 版权归属原作者,部分文章推送时未能及时与原作者取得联系,若来源标注错误或侵犯到您的权益烦请告知,我们将立即删除.

本文链接:https://www.xibujisuan.cn/22790.html

标签: WordPress