Get Category by Name

Retrieve the ID of the first item in a loop:

$category = get_the_category(); 
echo $category[0]->cat_name;

Retrieve the ID of the current category in the category.php or single.php page template:

$category = get_category( get_query_var( 'cat' ) );
$cat_id = $category->cat_ID;

Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.