WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get category by slug

Contents

Description

Retrieve category object by category slug. Returns false if not found.

Usage

<?php get_category_by_slug$slug ?>

Parameters

$slug
(string) (required) The category slug.
Default: None

Return Values

(object) 
Category data object.
(boolean) 
false if not found

Examples

<?php 
  $idObj = get_category_by_slug('category-slug'); 
  $id = $idObj->term_id;
?>

Notes

Change Log

Since: 2.3.0

Source File

get_category_by_slug() is located in wp-includes/category.php.

Related

See also index of Function Reference and index of Template Tags.