Ready to get started?Download WordPress


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

Function Reference/term exists


Check if a given term exists and return the term ID, a term array, or 0 (false) if the term doesn't exist.


<?php term_exists$term$taxonomy$parent ?>


(integer|string) (required) The term to check
Default: None
(string) (optional) The taxonomy name to use
Default: ''
(integer) (optional) $parent ID of parent term under which to confine the exists search
Default: 0

Return Values

  • Returns 0 or NULL if the term does not exist.
  • Returns the term ID if no taxonomy was specified and the term exists.
  • Returns an array if the pairing exists. (format: array('term_id'=>term id, 'term_taxonomy_id'=>taxonomy id))


Checks to see if 'Uncategorized' category exists

$term = term_exists('Uncategorized', 'category');
if ($term !== 0 && $term !== null) {
  echo "'Uncategorized' category exists!";

Checks to see if 'Untagged' post_tag category exists

$term = term_exists('Untagged', 'post_tag');
if ($term !== 0 && $term !== null) {
  echo "'Untagged' post_tag exists!";


  • Uses global: (object) $wpdb

Change Log

Since: 3.0

Source File

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


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