created_term
云策文档标注
概述
created_term 是一个 WordPress 动作钩子,在创建新分类法术语并清理术语缓存后触发。它允许开发者执行自定义操作,如日志记录或数据同步。
关键要点
- 触发时机:新术语创建后,术语缓存清理后
- 特定钩子:'created_$taxonomy' 可用于针对特定分类法
- 参数:$term_id(术语ID)、$tt_id(术语分类法ID)、$taxonomy(分类法slug)、$args(传递给 wp_insert_term() 的参数数组)
- 版本历史:6.1.0 版本添加了 $args 参数,2.3.0 版本引入
代码示例
do_action( 'created_term', $term_id, $tt_id, $taxonomy, $args );注意事项
- $args 参数包含 wp_insert_term() 的详细参数,如 alias_of、description、parent、slug 等
- 相关函数:wp_insert_term() 用于向数据库添加新术语
原文内容
Fires after a new term is created, and after the term cache has been cleaned.
Description
The ‘created_$taxonomy’ hook is also available for targeting a specific taxonomy.
Parameters
$term_idint-
Term ID.
$tt_idint-
Term taxonomy ID.
$taxonomystring-
Taxonomy slug.
$argsarray-
Arguments passed to wp_insert_term() .
More Arguments from wp_insert_term( … $args )
Array or query string of arguments for inserting a term.
alias_ofstringSlug of the term to make this term an alias of.
Accepts a term slug.descriptionstringThe term description.parentintThe id of the parent term. Default 0.slugstringThe term slug to use.
Source
do_action( 'created_term', $term_id, $tt_id, $taxonomy, $args );