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

Check whether a category exists.


Description

Top ↑

See also


Top ↑

Parameters

$cat_name int|string Required
Category name.
$category_parent int Optional
ID of parent category.

Default: null


Top ↑

Return

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


Top ↑

Source

File: wp-admin/includes/taxonomy.php. View all references

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;
}


Top ↑

Changelog

Changelog
Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.