Retrieves a category object by category slug.
Parameters
$slug
stringrequired- The category slug.
Source
function get_category_by_slug( $slug ) {
$category = get_term_by( 'slug', $slug, 'category' );
if ( $category ) {
_make_cat_compat( $category );
}
return $category;
}
Changelog
Version | Description |
---|---|
2.3.0 | Introduced. |
Returns false if not found
Example
Example migrated from Codex: