获取消毒的术语字段。
原型
get_term_field( string $field, int|WP_Term $term, string $taxonomy = '', string $context = 'display' )
描述
该功能是出于上下文原因和简化使用。
参考:
- sanitize_term_field()
参数
$field
(string)
(Required)
要获取的术语字段。
$term
(int|WP_Term)
(Required)
术语ID或对象。
$taxonomy
(string)
(Optional)
分类名称。
$context
(string)
(Optional)
默认是显示。查看sanitize_term_field()以获取可用选项。
返回值
(string|int|null|WP_Error)
如果$ term不是对象或者$ term中没有设置$ field,则返回空字符串。
源文件
路径:wp-includes/taxonomy.php
<?php
...
function get_term_field( $field, $term, $taxonomy = '', $context = 'display' ) {
$term = get_term( $term, $taxonomy );
if ( is_wp_error($term) )
return $term;
if ( !is_object($term) )
return '';
if ( !isset($term->$field) )
return '';
return sanitize_term_field( $field, $term->$field, $term->term_id, $term->taxonomy, $context );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/get_term_field/