WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/has term

Contents

Description

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.

Usage

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

Parameters

$term
(string|integer|array) (optional) The term name/term_id/slug or array of them to check for.
Default: ''
$taxonomy
(string) (required) Taxonomy name
Default: ''
$post
(integer|object) (optional) Post to check instead of the current post.
Default: null

Return Values

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

Examples

if( has_term( 'jazz', 'genre' ) ) {
    // do something
}

Notes

Change Log

Since: 3.1.0

Source File

has_term() is located in /wp-includes/category-template.php.

Related

See also index of Function Reference and index of Template Tags.