WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to get category ID of the current archive displayed.

I tried:

// category (can be a parent category)
$current_cat_ID = get_query_var('cat');
print_r ($current_cat_ID);

It doesn't print anything...

share|improve this question
where in the template is the code located? are there any custom queries before the code? – Michael Jul 24 '12 at 14:21
will cat always be set regardless of permalink structure, or maybe just category_name in some cases? I can't recall at the moment... – Milo Jul 24 '12 at 14:29
up vote 4 down vote accepted

you can use get_queried_object()

$category = get_queried_object();
echo $category->term_id;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.