钩子文档

{$taxonomy}_{$field}

💡 云策文档标注

概述

这是一个 WordPress 过滤器钩子,用于在显示前对分类法字段进行过滤和清理。它允许开发者自定义分类法字段的显示值。

关键要点

  • 过滤器名称是动态的,格式为 {$taxonomy}_{$field},其中 $taxonomy 是分类法 slug,$field 是分类法字段。
  • 参数包括 $value(字段值)、$term_id(术语 ID)和 $context(上下文),用于控制过滤逻辑。
  • 常用于 sanitize_term_field() 函数中,确保字段值在特定上下文中安全显示。

代码示例

$value = apply_filters( "{$taxonomy}_{$field}", $value, $term_id, $context );

注意事项

  • 此钩子自 WordPress 2.3.0 版本引入,使用时需确保兼容性。
  • 过滤器名称是动态构建的,需根据具体分类法和字段名来调用。

📄 原文内容

Filters the taxonomy field sanitized for display.

Description

The dynamic portions of the filter name, $taxonomy, and $field, refer to the taxonomy slug and taxonomy field, respectively.

Parameters

$valuemixed
Value of the taxonomy field.
$term_idint
Term ID.
$contextstring
Context to retrieve the taxonomy field value.

Source

$value = apply_filters( "{$taxonomy}_{$field}", $value, $term_id, $context );

Changelog

Version Description
2.3.0 Introduced.