get_cat_id

函数


get_cat_id ( $cat_name )
参数
  • (string)
    $cat_name
    Category name.
    Required:
返回值
  • (int) Category ID on success, 0 if the category doesn’t exist.
定义位置
  • wp-includes/category.php
    , line 205
引入
1.0.0
弃用

Retrieves the ID of a category from its name.

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