检查当前帖子是否包含任何给定条款。
原型
has_term( string|int|array $term = '', string $taxonomy = '', int|object $post = null )
描述
根据帖子的术语’term_ids,名称和slugs检查给定的术语。以整数形式给出的术语只会根据帖子的术语’term_ids进行检查。如果没有给出任何条款,则确定帖子是否有任何条款。
参数
$term
(string|int|array)
(Optional)
术语name / term_id / slug或要检查的数组。
$taxonomy
(string)
(Optional)
分类名称
$post
(int|object)
(Optional)
发布以检查而不是当前的帖子。
返回值
(bool)
如果当前帖子具有任何给定标签(或任何标签,如果未指定标签),则为True。
源文件
路径:wp-includes/category-template.php
<?php
...
function has_term( $term = '', $taxonomy = '', $post = null ) {
$post = get_post($post);
if ( !$post )
return false;
$r = is_object_in_term( $post->ID, $taxonomy, $term );
if ( is_wp_error( $r ) )
return false;
return $r;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/has_term/