钩子文档

get_terms_fields

💡 云策文档标注

概述

get_terms_fields 是一个 WordPress 过滤器,用于在查询术语时选择要返回的字段。它主要影响当 $fields 参数设置为 'count' 或 'all' 时的字段列表,但使用此过滤器可能导致不可预测的行为,不建议使用。

关键要点

  • 过滤器名称:get_terms_fields,用于修改术语查询中要选择的字段数组。
  • 适用场景:仅当 $fields 参数为 'count' 或 'all' 时生效,其他情况下由 $fields 参数单独决定。
  • 风险提示:使用此过滤器可能导致不可预测的行为,官方不推荐使用。
  • 参数:$selects(字段数组)、$args(查询参数数组)、$taxonomies(分类法名称数组)。
  • 源代码示例:$fields = implode(', ', apply_filters('get_terms_fields', $selects, $args, $taxonomies));
  • 相关函数:WP_Term_Query::get_terms(),用于检索查询结果。
  • 版本历史:自 WordPress 2.8.0 引入。

📄 原文内容

Filters the fields to select in the terms query.

Description

Field lists modified using this filter will only modify the term fields returned by the function when the $fields parameter set to ‘count’ or ‘all’. In all other cases, the term fields in the results array will be determined by the $fields parameter alone.

Use of this filter can result in unpredictable behavior, and is not recommended.

Parameters

$selectsstring[]
An array of fields to select for the terms query.
$argsarray
An array of term query arguments.
$taxonomiesstring[]
An array of taxonomy names.

Source

$fields = implode( ', ', apply_filters( 'get_terms_fields', $selects, $args, $taxonomies ) );

Changelog

Version Description
2.8.0 Introduced.