Skip to main content

Umm, I can't comment yet, but VicePrez's answer does work. The following works just fine on a category archive page (although you probably want to do something other than just echo it):

<?php
$category = get_the_category(); 
echo $category[0]->cat_ID;
?>

EDIT: Scratch that, it worked for me until I came across a category that didn't have a post, then it picked up the subcategory instead of the main category. You can't rely on get_the_category on a category template page.

Umm, I can't comment yet, but VicePrez's answer does work. The following works just fine on a category archive page (although you probably want to do something other than just echo it):

<?php
$category = get_the_category(); 
echo $category[0]->cat_ID;
?>

Umm, I can't comment yet, but VicePrez's answer does work. The following works just fine on a category archive page (although you probably want to do something other than just echo it):

<?php
$category = get_the_category(); 
echo $category[0]->cat_ID;
?>

EDIT: Scratch that, it worked for me until I came across a category that didn't have a post, then it picked up the subcategory instead of the main category. You can't rely on get_the_category on a category template page.

Source Link

Umm, I can't comment yet, but VicePrez's answer does work. The following works just fine on a category archive page (although you probably want to do something other than just echo it):

<?php
$category = get_the_category(); 
echo $category[0]->cat_ID;
?>