get_category_by_slug( string $slug )

Retrieves a category object by category slug.


Parameters Parameters

$slug

(string) (Required) The category slug.


Top ↑

Return Return

(object|false) Category data object on success, false if not found.


Top ↑

More Information More Information

Same is achieved by:
get_term_by('slug', $slug, 'category');


Top ↑

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


Top ↑

Changelog Changelog

Changelog
Version Description
2.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.