WordPress at a glance

get_category_by_slug() WP 1.0

Retrieve category object by category slug.

Works based on: get_term_by()
✈ 1 time = 0.000684s = slow | 50000 times = 18.52s = slow | PHP 7.0.2, WP 4.4.2

No Hooks.

Return

Object. Category data object

Usage

get_category_by_slug( $slug );
$slug(string) (required)
The category slug.

Code of get category by slug: wp-includes/category.php VER 5.1.1

<?php
function get_category_by_slug( $slug ) {
	$category = get_term_by( 'slug', $slug, 'category' );
	if ( $category ) {
		_make_cat_compat( $category );
	}

	return $category;
}

Related Functions

From category: Categories

No comments
    Hello, !     Log In . Register