Codex

Function Reference/term exists

Contents

Description

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

Usage

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

Parameters

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

Return Values

(mixed)
if term id or term exist: term id or, if $taxonomy wasn't empty, a Term Object (format: array('term_id'=>term id, 'term_taxonomy_id'=>taxonomy id))
false or 0
if term id or term does not exist

Examples

Checks to see if 'Uncategorized' category exists

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

Notes

  • Uses global: (object) $wpdb

Change Log

Since: 3.0

Source File

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

Related

Conditional Tags: comments_open(), is_404(), is_admin(), is_archive(), is_attachment(), is_author(), is_category(), is_comments_popup(), is_date(), is_day(), is_feed(), is_front_page(), is_home(), is_local_attachment(), is_multi_author, is_month(), is_new_day(), is_page(), is_page_template(), is_paged(), is_plugin_active(), is_plugin_active_for_network(), is_plugin_inactive(), is_plugin_page(), is_post_type_archive(), is_preview(), is_search(), is_single(), is_singular(), is_sticky(), is_tag(), is_tax(), is_taxonomy_hierarchical(), is_time(), is_trackback(), is_year(), in_category(), in_the_loop(), is_active_sidebar(), is_active_widget(), is_blog_installed(), is_rtl(), is_dynamic_sidebar(), is_user_logged_in(), has_excerpt(), has_post_thumbnail(), has_tag(), pings_open(), email exists(), post_type_exists(), taxonomy_exists(), term_exists(), username exists(), wp_attachment_is_image()

Terms: is_term(), term_exists(), get_objects_in_term(), get_term(), get_term_by(), get_term_children(), get_term_link(), get_terms(), get_the_terms(), get_the_term_list(), has_term(), sanitize term(), wp_get_object_terms(), wp_set_object_terms(), wp_get_post_terms(), wp_set_post_terms()

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