函数原型
get_category_by_slug( string $slug ): object|false
函数描述
Retrieves a category object by category slug.
是否弃用
未弃用
函数参数
-
$slug
string
Required - The category slug.
函数返回值
object|false Category data object on success, false if not found.
函数位置
File: wp-includes/category.php.
函数源码
function get_category_by_slug( $slug ) {
$category = get_term_by( 'slug', $slug, 'category' );
if ( $category ) {
_make_cat_compat( $category );
}
return $category;
}
源码链接
变更日志
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |

