函数原型
get_cat_ID( string $cat_name ): int
函数描述
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.
函数位置
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;
}
源码链接
变更日志
| Version | Description |
|---|---|
| 1.0.0 | Introduced. |

