wpseek.com
A WordPress-centric search engine for devs and theme authors



get_cat_id › WordPress Function

Since1.0.0
Deprecatedn/a
get_cat_id ( $cat_name )
Parameters:
  • (string) $cat_name Category name.
    Required: Yes
Returns:
  • (int) Category ID on success, 0 if the category doesn't exist.
Defined at:
Codex:

Retrieves the ID of a category from its name.



Source

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