钩子文档

found_comments_query

💡 云策文档标注

概述

found_comments_query 是一个 WordPress 过滤器,用于修改检索找到的评论数量时使用的 SQL 查询。它允许开发者自定义查询逻辑,例如优化性能或调整计数方式。

关键要点

  • 过滤器名称:found_comments_query
  • 参数:$found_comments_query(SQL 查询字符串,默认为 'SELECT FOUND_ROWS()')和 $comment_query(WP_Comment_Query 实例)
  • 用途:在 WP_Comment_Query 中设置 found_comments 和 max_num_pages 属性时,如果使用了限制子句,此过滤器可以干预查询过程
  • 引入版本:4.4.0
  • 相关函数:WP_Comment_Query::set_found_comments()

📄 原文内容

Filters the query used to retrieve found comment count.

Parameters

$found_comments_querystring
SQL query. Default ‘SELECT FOUND_ROWS()’.
$comment_queryWP_Comment_Query
The WP_Comment_Query instance.

Source

$found_comments_query = apply_filters( 'found_comments_query', 'SELECT FOUND_ROWS()', $this );

Changelog

Version Description
4.4.0 Introduced.