get_cat_ID()

最后更新于:2021-11-26 07:32:20

get_cat_ID( string$cat_name)

Retrieves the ID of a category from its name.

参数

$cat_name

(string) (Required) Category name.

响应

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

源文件

文件: gc-includes/category.php

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

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

	return 0;
}