has_term()判断当前页面是否带有自定义分类

目录

描述

Check if the current post has any of the given terms.

The given terms are checked against the post's terms' term_ids, names, and slugs. Terms given as integers will only be checked against the post's terms' term_ids.

If no terms are given, determines if post has any terms.

has_term() 描述

用法

<?php has_term$term$taxonomy$post ?>

has_term() 用法

参数

$term

(string|integer|array) (可选) The term name/term_id/slug or array of them to check for.

默认值: ''

$taxonomy

(string) (必填) Taxonomy name

默认值: ''

$post

(integer|object) (可选) Post to check instead of the current post.

默认值: null

has_term() 参数

返回值

(boolean) 

True if the current post has any of the given terms (or any term, if no term is specified).

has_term() 返回值

示例

has_term() 示例

历史

添加于 版本: 3.1.0

has_term() 历史

源文件

has_term() 函数的代码位于 /wp-includes/category-template.php.

has_term() 源文件

相关