has_term()
最后更新于:2021-11-27 05:20:07
has_term( string|int|array$term=”, string$taxonomy=”, int|GC_Post$post=null)Checks if the current post has any of given terms.
参数
- $term
-
(string|int|array) (Optional) The term name/term_id/slug, or an array of them to check for.
Default value: ”
- $taxonomy
-
(string) (Optional) Taxonomy name.
Default value: ”
- $post
-
(int|GC_Post) (Optional) Post to check instead of the current post.
Default value: null
响应
(bool) True if the current post has any of the given terms (or any term, if no term specified). False otherwise.
源文件
文件: gc-includes/category-template.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_gc_error( $r ) ) {
return false;
}
return $r;
}