钩子文档

wp_count_comments

💡 云策文档标注

概述

wp_count_comments 是一个 WordPress 过滤器,用于修改特定文章或整个网站的评论计数。它允许开发者在获取评论统计时自定义数据。

关键要点

  • 过滤器名称:wp_count_comments
  • 参数:$count(数组或对象,包含评论计数)和 $post_id(整数,文章 ID,0 表示整个网站)
  • 应用场景:在 wp_count_comments() 函数中调用,用于过滤评论统计结果

代码示例

$filtered = apply_filters( 'wp_count_comments', array(), $post_id );

注意事项

  • 引入版本:WordPress 2.7.0
  • 相关函数:wp_count_comments(),位于 wp-includes/comment.php

📄 原文内容

Filters the comments count for a given post or the whole site.

Parameters

$countarray|stdClass
An empty array or an object containing comment counts.
$post_idint
The post ID. Can be 0 to represent the whole site.

Source

$filtered = apply_filters( 'wp_count_comments', array(), $post_id );

Changelog

Version Description
2.7.0 Introduced.