Title: term_exists
Published: April 25, 2014
Last modified: August 20, 2026

---

# term_exists( int|string|null $term, string $taxonomy = ”, int $parent_term = null ): mixed

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#user-contributed-notes)

Determines whether a taxonomy term exists.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#description)󠁿

Formerly [is_term()](https://developer.wordpress.org/reference/functions/is_term/),
introduced in 2.3.0.

For more information on this and similar theme functions, check out the [Conditional Tags](https://developer.wordpress.org/themes/basics/conditional-tags/)
article in the Theme Developer Handbook.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#parameters)󠁿

 `$term`int|string|nullrequired

The term to check. Accepts term ID, slug, or name.

`$taxonomy`stringoptional

The taxonomy name to use.

Default:`''`

`$parent_term`intoptional

ID of parent term under which to confine the exists search.

Default:`null`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#return)󠁿

 mixed Returns null if the term does not exist.
 Returns the term ID if no taxonomy
is specified and the term ID exists. Returns an array of the term ID and the term
taxonomy ID if the taxonomy is specified and the pairing exists. Returns 0 if term
ID 0 is passed to the function.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#source)󠁿

    ```php
    function term_exists( $term, $taxonomy = '', $parent_term = null ) {
    	global $_wp_suspend_cache_invalidation;

    	if ( null === $term ) {
    		return null;
    	}

    	$defaults = array(
    		'get'                    => 'all',
    		'fields'                 => 'ids',
    		'number'                 => 1,
    		'update_term_meta_cache' => false,
    		'order'                  => 'ASC',
    		'orderby'                => 'term_id',
    		'suppress_filter'        => true,
    	);

    	// Ensure that while importing, queries are not cached.
    	if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
    		$defaults['cache_results'] = false;
    	}

    	if ( ! empty( $taxonomy ) ) {
    		$defaults['taxonomy'] = $taxonomy;
    		$defaults['fields']   = 'all';
    	}

    	/**
    	 * Filters default query arguments for checking if a term exists.
    	 *
    	 * @since 6.0.0
    	 *
    	 * @param array      $defaults    An array of arguments passed to get_terms().
    	 * @param int|string $term        The term to check. Accepts term ID, slug, or name.
    	 * @param string     $taxonomy    The taxonomy name to use. An empty string indicates
    	 *                                the search is against all taxonomies.
    	 * @param int|null   $parent_term ID of parent term under which to confine the exists search.
    	 *                                Null indicates the search is unconfined.
    	 */
    	$defaults = apply_filters( 'term_exists_default_query_args', $defaults, $term, $taxonomy, $parent_term );

    	if ( ! empty( $taxonomy ) && is_numeric( $parent_term ) ) {
    		$defaults['parent'] = (int) $parent_term;
    	}

    	if ( is_int( $term ) ) {
    		if ( 0 === $term ) {
    			return 0;
    		}
    		$args  = wp_parse_args( array( 'include' => array( $term ) ), $defaults );
    		$terms = get_terms( $args );
    	} else {
    		$term = trim( wp_unslash( $term ) );
    		if ( '' === $term ) {
    			return null;
    		}

    		$args  = wp_parse_args( array( 'slug' => sanitize_title( $term ) ), $defaults );
    		$terms = get_terms( $args );
    		if ( empty( $terms ) || is_wp_error( $terms ) ) {
    			$args  = wp_parse_args( array( 'name' => $term ), $defaults );
    			$terms = get_terms( $args );
    		}
    	}

    	if ( empty( $terms ) || is_wp_error( $terms ) ) {
    		return null;
    	}

    	$_term = array_shift( $terms );

    	if ( ! empty( $taxonomy ) ) {
    		return array(
    			'term_id'          => (string) $_term->term_id,
    			'term_taxonomy_id' => (string) $_term->term_taxonomy_id,
    		);
    	}

    	return (string) $_term;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/taxonomy.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/taxonomy.php#L1605)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/taxonomy.php#L1605-L1684)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#hooks)󠁿

 [apply_filters( ‘term_exists_default_query_args’, array $defaults, int|string $term, string $taxonomy, int|null $parent_term )](https://developer.wordpress.org/reference/hooks/term_exists_default_query_args/)

Filters default query arguments for checking if a term exists.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#related)󠁿

| Uses | Description | 
| [sanitize_title()](https://developer.wordpress.org/reference/functions/sanitize_title/)`wp-includes/formatting.php` |

Sanitizes a string into a slug, which can be used in URLs or HTML attributes.

  | 
| [get_terms()](https://developer.wordpress.org/reference/functions/get_terms/)`wp-includes/taxonomy.php` |

Retrieves the terms in a given taxonomy or list of taxonomies.

  | 
| [wp_unslash()](https://developer.wordpress.org/reference/functions/wp_unslash/)`wp-includes/formatting.php` |

Removes slashes from a string or recursively removes slashes from strings within an array.

  | 
| [wp_parse_args()](https://developer.wordpress.org/reference/functions/wp_parse_args/)`wp-includes/functions.php` |

Merges user defined arguments into defaults array.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)`wp-includes/load.php` |

Checks whether the given variable is a WordPress Error.

  |

[Show 4 more](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#)

| Used by | Description | 
| [export_wp()](https://developer.wordpress.org/reference/functions/export_wp/)`wp-admin/includes/export.php` |

Generates the WXR export file for download.

  | 
| [category_exists()](https://developer.wordpress.org/reference/functions/category_exists/)`wp-admin/includes/taxonomy.php` |

Checks whether a category exists.

  | 
| [wp_insert_category()](https://developer.wordpress.org/reference/functions/wp_insert_category/)`wp-admin/includes/taxonomy.php` |

Updates an existing Category or creates a new Category.

  | 
| [tag_exists()](https://developer.wordpress.org/reference/functions/tag_exists/)`wp-admin/includes/taxonomy.php` |

Checks whether a post tag with a given name exists.

  | 
| [wp_create_term()](https://developer.wordpress.org/reference/functions/wp_create_term/)`wp-admin/includes/taxonomy.php` |

Adds a new term to the database if it does not already exist.

  | 
| [is_term()](https://developer.wordpress.org/reference/functions/is_term/)`wp-includes/deprecated.php` |

Check if Term exists.

  | 
| [wp_unique_term_slug()](https://developer.wordpress.org/reference/functions/wp_unique_term_slug/)`wp-includes/taxonomy.php` |

Makes term slug unique, if it isn’t already.

  | 
| [wp_update_term()](https://developer.wordpress.org/reference/functions/wp_update_term/)`wp-includes/taxonomy.php` |

Updates term based on arguments provided.

  | 
| [wp_insert_term()](https://developer.wordpress.org/reference/functions/wp_insert_term/)`wp-includes/taxonomy.php` |

Adds a new term to the database.

  | 
| [wp_set_object_terms()](https://developer.wordpress.org/reference/functions/wp_set_object_terms/)`wp-includes/taxonomy.php` |

Creates term and taxonomy relationships.

  | 
| [wp_remove_object_terms()](https://developer.wordpress.org/reference/functions/wp_remove_object_terms/)`wp-includes/taxonomy.php` |

Removes term(s) associated with a given object.

  | 
| [wp_delete_term()](https://developer.wordpress.org/reference/functions/wp_delete_term/)`wp-includes/taxonomy.php` |

Removes a term from the database.

  | 
| [register_taxonomy()](https://developer.wordpress.org/reference/functions/register_taxonomy/)`wp-includes/taxonomy.php` |

Creates or modifies a taxonomy object.

  |

[Show 8 more](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.0.0](https://developer.wordpress.org/reference/since/6.0.0/) | Converted to use `get_terms()`. | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#comment-content-857)
 2.    [Maje Media LLC](https://profiles.wordpress.org/majemedia/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/term_exists/#comment-857)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fterm_exists%2F%23comment-857)
     Vote results for this note: 5[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fterm_exists%2F%23comment-857)
 4.  The returned array of
 5.      ```php
         ['term_id' => ID, 'term_taxonomy_id' => ID]
         ```
     
 6.   returns a string for the ID instead of ints. If you need int values you’ll need
     to convert them to ints.
 7.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fterm_exists%2F%3Freplytocom%3D857%23feedback-editor-857)
 8.   [Skip to note 5 content](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#comment-content-644)
 9.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/term_exists/#comment-644)
 10. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fterm_exists%2F%23comment-644)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fterm_exists%2F%23comment-644)
 11. **Checks to see if ‘Uncategorized’ category exists**
      **Check if the ‘Uncategorized’
     category exists** Note: `term_exists()` runs a database query. `get_term()` can
     be used for the same purpose, except it uses the term cache.
 12.     ```php
         $term = term_exists( 'Uncategorized', 'category' );
         if ( $term !== 0 && $term !== null ) {
         	echo __( "'Uncategorized' category exists!", "textdomain" );
         }
         ```
     
 13.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fterm_exists%2F%3Freplytocom%3D644%23feedback-editor-644)
 14.  [Skip to note 6 content](https://developer.wordpress.org/reference/functions/term_exists/?output_format=md#comment-content-645)
 15.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/term_exists/#comment-645)
 16. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fterm_exists%2F%23comment-645)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fterm_exists%2F%23comment-645)
 17. **Checks to see if ‘Untagged’ post_tag category exists**
      Note: `term_exists()`
     runs a database query. `get_term()` can be used for the same purpose, except it
     uses the term cache.
 18.     ```php
         $term = term_exists( 'Untagged', 'post_tag' );
         if ( $term !== 0 && $term !== null ) {
         	echo __( "'Untagged' post_tag exists!", "textdomain" );
         }
         ```
     
 19.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fterm_exists%2F%3Freplytocom%3D645%23feedback-editor-645)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fterm_exists%2F)
before being able to contribute a note or feedback.