WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/is object in term

Description

Determines if the given object is associated with any of the given terms.

The given terms are checked against the object’s terms’ term_ids, names and slugs. Terms given as integers will only be checked against the object’s terms’ term_ids. If no terms are given, determines if object is associated with any terms in the given taxonomy.

Usage

<?php is_object_in_term$object_id$taxonomy$terms null ?>

Parameters

$object_id
(integer) (required) ID of the object to check. (post ID, link ID, etc.)
Default: None
$taxonomy
(string) (required) A single taxonomy name.
Default: None
$terms
(mixed) (optional) The term ID, name or slug or an array of such.
Default: NULL

Return Values

(boolean|mixed)
True if associated, false if not associated. WP_Error on input error.

Examples

<?php
if ( is_object_in_term( $post->ID, 'custom_taxonomy_name', 'term_name' ) ) :
	echo 'YES';
else :
	echo 'NO';
endif;
?>

Notes

Change log

Since: 2.7.0

Source File

is_object_in_term() is located in wp-includes/taxonomy.php.

Related

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