Title: category_exists
Published: April 25, 2014
Last modified: February 24, 2026

---

# category_exists( int|string $cat_name, int $category_parent = null ): string|null

## In this article

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

[ Back to top](https://developer.wordpress.org/reference/functions/category_exists/?output_format=md#wp--skip-link--target)

Checks whether a category exists.

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

### 󠀁[See also](https://developer.wordpress.org/reference/functions/category_exists/?output_format=md#see-also)󠁿

 * [term_exists()](https://developer.wordpress.org/reference/functions/term_exists/)

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

 `$cat_name`int|stringrequired

Category name.

`$category_parent`intoptional

ID of parent category.

Default:`null`

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

 string|null Returns the category ID as a numeric string if the pairing exists, 
null if not.

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

    ```php
    function category_exists( $cat_name, $category_parent = null ) {
    	$id = term_exists( $cat_name, 'category', $category_parent );
    	if ( is_array( $id ) ) {
    		$id = $id['term_id'];
    	}
    	return $id;
    }
    ```

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

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

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

Determines whether a taxonomy term exists.

  |

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

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

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

Creates categories for the given post.

  |

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

| Version | Description | 
| [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. |

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

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/category_exists/?output_format=md#comment-content-2916)
 2.   [keesiemeijer](https://profiles.wordpress.org/keesiemeijer/)  [  7 years ago  ](https://developer.wordpress.org/reference/functions/category_exists/#comment-2916)
 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%2Fcategory_exists%2F%23comment-2916)
    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%2Fcategory_exists%2F%23comment-2916)
 4. Beware this function is only available in the wp-admin and will throw an error 
    if used in the front end of your site. Use [term_exists](https://developer.wordpress.org/reference/functions/term_exists/)
    instead.
 5.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fcategory_exists%2F%3Freplytocom%3D2916%23feedback-editor-2916)

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