get_category_by_slug

Retrieve category object by category slug.

Description

(object) get_category_by_slug( (string) $slug ); 

Returns (object)

Category data object

Parameters (1)

0. $slug (string)
The category slug.

Usage

  1. if ( !function_exists( 'get_category_by_slug' ) ) { 
  2. require_once ABSPATH . WPINC . '/category.php'; 
  3.  
  4. // The category slug. 
  5. $slug = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_category_by_slug($slug); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/category.php  
  1. function get_category_by_slug( $slug ) { 
  2. $category = get_term_by( 'slug', $slug, 'category' ); 
  3. if ( $category ) 
  4. _make_cat_compat( $category ); 
  5.  
  6. return $category;