钩子文档

get_usernumposts

💡 云策文档标注

概述

get_usernumposts 是一个 WordPress 过滤器钩子,用于过滤用户撰写的文章数量。它允许开发者修改基于用户 ID、文章类型和可见性条件计算出的文章计数。

关键要点

  • 这是一个过滤器钩子,用于修改用户文章数量。
  • 参数包括用户 ID、文章类型和是否仅计算公开文章。
  • 钩子返回应用过滤器后的文章计数。

代码示例

apply_filters( 'get_usernumposts', $count, $userid, $post_type, $public_only );

注意事项

  • 参数 $post_type 可以是字符串或数组,用于指定要计数的文章类型。
  • 参数 $public_only 控制是否仅计算公开文章,从版本 4.3.1 开始引入。
  • 相关函数 count_user_posts() 用于获取用户文章数量。

📄 原文内容

Filters the number of posts a user has written.

Parameters

$countstring
The user’s post count as a numeric string.
$useridint
User ID.
$post_typestring|array
Single post type or array of post types to count the number of posts for.
$public_onlybool
Whether to limit counted posts to public posts.

Source

return apply_filters( 'get_usernumposts', $count, $userid, $post_type, $public_only );

Changelog

Version Description
4.3.1 Added $public_only argument.
4.1.0 Added $post_type argument.
2.7.0 Introduced.