count_user_posts()获取用户发布的文章数

目录

描述

Returns the post count for a user.

count_user_posts() 描述

用法

<?php $user_post_count count_user_posts$userid $post_type ); ?>

count_user_posts() 用法

参数

$userid

(integer) (必填) The ID of the user to count posts for.

默认值: None

$post_type

(string) (可选) Post type to count the number of posts for.

默认值: "post"

count_user_posts() 参数

示例

Get post count for a user

Display the number of posts published by the user with an ID of 5.

Get post count for a user of post type

Display the number of posts of post type "book" published by the user with an ID of 5.

Translation friendly post count

The same operation, with translation support.

Result

The result of the above two examples

Number of posts published by user: 123

count_user_posts() 示例

历史

  • 添加于 版本: 3.0.0
  • 添加于 版本: 4.1.0 (Added post type support)

count_user_posts() 历史

源文件

count_user_posts() 函数的代码位于 wp-includes/user.php.

count_user_posts() 源文件

相关