W3cubDocs

/WordPress

get_category_by_slug( string $slug )

Retrieve category object by category slug.

Description

Parameters

$slug

(string) (Required) The category slug.

Return

(object) Category data object

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;
}

Changelog

Version Description
2.3.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_category_by_slug