函数原型
category_exists( int|string $cat_name, int $category_parent = null ): string|null
函数描述
Checks whether a category exists.
是否弃用
未弃用
函数参数
-
$cat_name
int|string
Required - Category name.
-
$category_parent
int
Optional - ID of parent category.
Default:
null
函数返回值
string|null Returns the category ID as a numeric string if the pairing exists, null if not.
函数位置
File: wp-admin/includes/taxonomy.php.
函数源码
function category_exists( $cat_name, $category_parent = null ) {
$id = term_exists( $cat_name, 'category', $category_parent );
if ( is_array( $id ) ) {
$id = $id['term_id'];
}
return $id;
}
源码链接
变更日志
| Version | Description |
|---|---|
| 2.0.0 | Introduced. |

