WordPress at a glance

get_cat_ID() WP 1.0

Retrieve the ID of a category from its name.

Works based on: get_term_by()

No Hooks.


Int. Category ID on success, 0 if the category doesn't exist.


get_cat_ID( $cat_name ) // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid;
$cat_name(string) (required)
Category name.


Since 1.0.0 Introduced.

Code of get_cat_ID() WP 5.7.2

function get_cat_ID( $cat_name ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
	$cat = get_term_by( 'name', $cat_name, 'category' );

	if ( $cat ) {
		return $cat->term_id;

	return 0;

From category: Categories

No comments
    Log In