钩子文档

pre_count_many_users_posts

💡 云策文档标注

概述

pre_count_many_users_posts 是一个 WordPress 过滤器,用于在计算多个用户的文章数量时提供短路机制。开发者可以通过此过滤器自定义返回文章计数数组,从而优化性能或实现特定逻辑。

关键要点

  • 过滤器名称:pre_count_many_users_posts
  • 主要用途:允许在 count_many_users_posts() 函数执行前短路文章计数计算,返回自定义的计数数组
  • 返回值:应返回一个数组,键为用户 ID,值为文章计数字符串;返回非 null 值以触发短路
  • 参数:包括 $users(用户 ID 数组)、$post_type(文章类型)、$public_only(是否仅公开文章)
  • 引入版本:WordPress 6.8.0

代码示例

$pre = apply_filters( 'pre_count_many_users_posts', null, $users, $post_type, $public_only );

📄 原文内容

Filters whether to short-circuit performing the post counts.

Description

When filtering, return an array of posts counts as strings, keyed by the user ID.

Parameters

$countstring[]|null
The post counts. Return a non-null value to short-circuit.
$usersint[]
Array of user IDs.
$post_typestring|string[]
Single post type or array of post types to check.
$public_onlybool
Whether to only return counts for public posts.

Source

$pre = apply_filters( 'pre_count_many_users_posts', null, $users, $post_type, $public_only );

Changelog

Version Description
6.8.0 Introduced.