get_category_by_slug() WP 1.0
Retrieve category object by category slug.
Works based on: get_term_by(), _make_cat_compat()
1 time = 0.000684s = slow | 50000 times = 18.52s = slow | PHP 7.0.2, WP 4.4.2
No Hooks.
Return
Object/false. Category data object on success, false if not found.
Usage
get_category_by_slug( $slug );
- $slug(string) (required)
- The category slug.
Changelog
Since 2.3.0 | Introduced. |
Code of get_category_by_slug() get category by slug WP 5.6
function get_category_by_slug( $slug ) {
$category = get_term_by( 'slug', $slug, 'category' );
if ( $category ) {
_make_cat_compat( $category );
}
return $category;
}