wp_get_term_taxonomy_parent_id()
云策文档标注
概述
wp_get_term_taxonomy_parent_id() 函数用于获取指定分类术语的父术语 ID。它接受术语 ID 和分类法名称作为参数,返回父术语 ID 或失败时返回 false。
关键要点
- 函数返回术语的父术语 ID,成功时返回整数,失败时返回 false。
- 参数包括必需的 $term_id(整数类型)和 $taxonomy(字符串类型)。
- 内部使用 get_term() 获取术语数据,并检查是否为 WP_Error。
- 自 WordPress 3.1.0 版本引入。
代码示例
function wp_get_term_taxonomy_parent_id( $term_id, $taxonomy ) {
$term = get_term( $term_id, $taxonomy );
if ( ! $term || is_wp_error( $term ) ) {
return false;
}
return (int) $term->parent;
}
原文内容
Returns the term’s parent’s term ID.
Parameters
$term_idintrequired-
Term ID.
$taxonomystringrequired-
Taxonomy name.
Source
function wp_get_term_taxonomy_parent_id( $term_id, $taxonomy ) {
$term = get_term( $term_id, $taxonomy );
if ( ! $term || is_wp_error( $term ) ) {
return false;
}
return (int) $term->parent;
}
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |