钩子文档

posts_fields

💡 云策文档标注

概述

posts_fields 过滤器用于修改 WP_Query 查询中的 SELECT 子句,允许开发者自定义查询返回的字段。它接收查询的 SELECT 子句字符串和 WP_Query 实例作为参数。

关键要点

  • 过滤器名称:posts_fields
  • 作用:过滤 WP_Query 查询的 SELECT 子句
  • 参数:$fields(SELECT 子句字符串)和 $query(WP_Query 实例,通过引用传递)
  • 相关函数:在 WP_Query::get_posts() 中调用
  • 引入版本:WordPress 2.1.0

📄 原文内容

Filters the SELECT clause of the query.

Parameters

$fieldsstring
The SELECT clause of the query.
$queryWP_Query
The WP_Query instance (passed by reference).

Source

$fields = apply_filters_ref_array( 'posts_fields', array( $fields, &$this ) );

Changelog

Version Description
2.1.0 Introduced.