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

Checks whether a category exists.

Description

See also

Parameters

$cat_nameint|stringrequired
Category name.
$category_parentintoptional
ID of parent category.

Default:null

Return

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

Source

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

Changelog

VersionDescription
2.0.0Introduced.

User Contributed Notes

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