WordPress at Your Fingertips

get_category_by_slug() WP 1.0

Retrieve category object by category slug.

1 time — 0.000684 sec (slow) | 50000 times — 18.52 sec (slow) | PHP 7.0.2, WP 4.4.2

No Hooks.

Return

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

Usage

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

Changelog

Since 2.3.0 Introduced.

Code of get_category_by_slug() WP 5.8

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

	if ( $category ) {
		_make_cat_compat( $category );
	}

	return $category;
}

From category: Categories

No comments
    Log In