get_cat_ID

Advertisement

Summery Summery

Retrieves the ID of a category from its name.

Syntax Syntax

get_cat_ID( string $cat_name )

Parameters Parameters

$cat_name

(Required) Category name.

Return Return

(int) Category ID on success, 0 if the category doesn't exist.

Source Source

File: wp-includes/category.php

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

Advertisement

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.

Advertisement

Leave a Reply