Codex

Function Reference/get cat ID

Contents

Description

Retrieve the ID of a category from its name.

Usage

<?php get_cat_ID$cat_name ?>

Parameters

$cat_name
(string) (optional) Default is 'General' and can be any category name.
Default: 'General'

Return Values

(integer) 
0, if failure and ID of category on success.

Examples

Basic

This is a very basic example of how to use this function in The_Loop.

<?php
     $category_id = get_cat_id('Category Name');
     $q = 'cat=' . $category_id;
     query_posts($q);
     if (have_posts()) : while (have_posts()) : the_post();

     the_content();

     endwhile; endif;
?>

Notes

Change Log

Since: 1.0.0

Source File

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

Related