comments_array
云策文档标注
概述
comments_array 是一个 WordPress 过滤器,用于修改传递给评论模板的评论数组。它允许开发者在评论查询过程中拦截和调整评论数据。
关键要点
- 过滤器名称:comments_array
- 参数:$comments(评论数组)和 $post_id(文章 ID)
- 用途:在 comments_template() 函数内部使用,用于处理文章评论查询
- 源位置:$wp_query->comments = apply_filters( 'comments_array', $comments_flat, $post->ID );
代码示例
add_filter( 'comments_array', '__return_empty_array' );注意事项
此过滤器自 WordPress 2.1.0 版本引入,可用于隐藏所有现有评论,例如通过返回空数组。
原文内容
Filters the comments array.
Parameters
$commentsarray-
Array of comments supplied to the comments template.
$post_idint-
Post ID.
Source
$wp_query->comments = apply_filters( 'comments_array', $comments_flat, $post->ID );
Changelog
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |
Skip to note 2 content
Ethan O’Sullivan
If you want to hide all of the existing comments for your posts, use the following function to return an empty array:
add_filter( 'comments_array', '__return_empty_array' );