Function: has_term

has_term( string | integer | array $term, string $taxonomy, integer | object $post )

Check if the current post has any of given terms.

Shortcut: ht

You can use above key combination to trigger the associated snippet for this function in the WordPress Snippets for Visual Studio Code extension. You can also use this shortcut to search for this function on this website.

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.

Parameters

Name Type(s) Default Value Description
$term string | integer | array ''

Optional. The term name/term_id/slug or array of them to check for.

$taxonomy string ''

Taxonomy name

$post integer | object null

Optional. Post to check instead of the current post.

Returns

boolean

True if the current post has any of the given tags (or any tag, if no tag specified).

WordPress Developer Newsletter

Stay informed of new chapter releases, important WordPress API updates and more.