Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 1 down vote accepted

you can use get_queried_object()

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

Your Answer

 
discard

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.