wppaste
WordPress

has_term( string|int|array $term = '', string $taxonomy = '', int|WP_Post|null $post = null ): bool

Since
3.1.0
Source
wp-includes/category-template.php:1542
Checks if the current post has any of given terms.

Description

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

$termstring|int|arrayoptional
The term name/term_id/slug, or an array of them to check for. Default empty.Default: ''
$taxonomystringoptional
Taxonomy name. Default empty.Default: ''
$postint|WP_Post|nulloptional
Post to check. Defaults to the current post.Default: null

Return

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

Uses · 3

  • get_post()Retrieves post data given a post ID or post object.
  • is_object_in_term()Determines if the given object is associated with any of the given terms.
  • is_wp_error()Checks whether the given variable is a WordPress Error.

Used by · 4

Source

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;}

History

Introduced in 3.1.0. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.0.4
Parameter $post retyped from int|WP_Post to int|WP_Post|null.verified against source
3.1.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/category-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.