get_category_by_slug( string $slug )
Retrieve category object by category slug.
Description Description
Parameters Parameters
- $slug
-
(string) (Required) The category slug.
Return Return
(object) Category data object
Source Source
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;
}
Expand full source code Collapse full source code View on Trac
Changelog Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Returns false if not found
Example
$idObj = get_category_by_slug( 'category-slug' ); if ( $idObj instanceof WP_Term ) { $id = $idObj->term_id; }