term_exists()

This WordPress function requires the CPT-onomy class.

Description

Checks to see if a term exists.

If a given term exists, it returns the term object. Returns 0 (false) if the term does not exist.

Usage

$cpt_onomy->term_exists( 						string|int
						$term
						, 						string
						$cpt_onomy
						, 						string|int
						$parent
						 );

Parameters

$term (string|integer) (required)
Default: none
The term to check. Can be the term id, name or slug.

$cpt_onomy (string) (optional)
Default: none
The name of the CPT-onomy that the term belongs to.

$parent (string|integer) (optional)
Default: none
Term ID of parent term if you want to limit the search.

Return Values

(object|false|0) If a given term exists, it returns the term object. Returns 0 (false) if the term does not exist.

Term object fields:

  • term_id
  • name
  • slug
  • term_group
  • term_taxonomy_id
  • taxonomy
  • description
  • parent
  • count

WordPress Codex

For more information, refer to the WordPress codex.