the_posts
云策文档标注
概述
the_posts 是一个 WordPress 过滤器钩子,用于在文章被获取并内部处理后,对检索到的文章数组进行过滤。它允许开发者在查询结果返回前修改文章数据。
关键要点
- the_posts 是一个过滤器钩子,作用于 WP_Query 检索到的文章数组。
- 它接收两个参数:$posts(文章对象数组)和 $query(WP_Query 实例,通过引用传递)。
- 常用于在文章显示前对查询结果进行自定义修改或处理。
代码示例
$this->posts = apply_filters_ref_array( 'the_posts', array( $this->posts, &$this ) );注意事项
- the_posts 钩子在 WP_Query::get_posts() 方法中被调用,用于最终处理查询结果。
- 自 WordPress 1.5.0 版本引入,是一个核心钩子。
原文内容
Filters the array of retrieved posts after they’ve been fetched and internally processed.
Parameters
Source
$this->posts = apply_filters_ref_array( 'the_posts', array( $this->posts, &$this ) );
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |