On this page
get_category_by_slug( string $slug ): object|false
Retrieves a category object by category slug.
Parameters
$slugstring Required-
The category slug.
Return
object|false Category data object on success, false if not found.
More Information
Same is achieved by:
get_term_by('slug', $slug, 'category');
Source
File: wp-includes/category.php. View all references
function get_category_by_slug( $slug ) {
$category = get_term_by( 'slug', $slug, 'category' );
if ( $category ) {
_make_cat_compat( $category );
}
return $category;
}
Related
Uses
| Uses | Description |
|---|---|
| _make_cat_compat() wp-includes/category.php | Updates category structure to old pre-2.3 from new taxonomy structure. |
| get_term_by() wp-includes/taxonomy.php | Gets all term data from database by term field and data. |
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_category_by_slug