钩子文档

get_{$taxonomy}

💡 云策文档标注

概述

本文档介绍 WordPress 中的 get_{$taxonomy} 过滤器,用于过滤分类法术语对象。该过滤器是动态的,$taxonomy 部分指代术语所属分类法的 slug。

关键要点

  • 过滤器名称是动态的,例如 get_category 或 get_post_tag,具体取决于分类法 slug。
  • 参数包括 $_term(WP_Term 对象)和 $taxonomy(分类法 slug 字符串)。
  • 在 WordPress 4.4.0 版本中,$_term 参数从其他类型更新为 WP_Term 对象。

代码示例

$_term = apply_filters( "get_{$taxonomy}", $_term, $taxonomy );

注意事项

  • 此过滤器在 get_term() 函数中被调用,用于从数据库获取术语数据。
  • 引入于 WordPress 2.3.0 版本,并在 4.4.0 版本中进行了参数类型更新。

📄 原文内容

Filters a taxonomy term object.

Description

The dynamic portion of the hook name, $taxonomy, refers to the slug of the term’s taxonomy.

Possible hook names include:

  • get_category
  • get_post_tag

Parameters

$_termWP_Term
Term object.
$taxonomystring
The taxonomy slug.

Source

$_term = apply_filters( "get_{$taxonomy}", $_term, $taxonomy );

Changelog

Version Description
4.4.0 $_term is now a WP_Term object.
2.3.0 Introduced.