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 want to get the current category details that the user is on in category.php.

$category = get_the_category();
$slug  = $category[0]->slug; // Why is this an array ?

In most cases (where there are no sub-categories) it returns and array of single length.

But if there are sub-categories it (parent category and ) returns an array of 2 or more.

http://domain.com/category/cat-name/ -> get_the_category() returns an array of 2
http://domain.com/category/cat-name/sub-cat-name/ -> get_the_category() returns an array of 2
share|improve this question
You seem to be getting categories. What is the question? – s_ha_dum Dec 11 '12 at 15:21
I want the current category the page is on at category.php. For categories that have sub-categories, I'm getting an array of categories - how can I make out which is the current category ? – EPQRS Dec 11 '12 at 16:54
up vote 2 down vote accepted

You are using the wrong function. Try:

$thiscat = $wp_query->get_queried_object();

I don't know exactly what you want to do with this information but you will get an object (stdClass) with ~15 items in it. You should be able to find what you need.

share|improve this answer
Thanks. This worked. – EPQRS Dec 12 '12 at 6:29

I normally use the following to retrieve the category ID of the current category archive:

$cat_id = get_query_var('cat')

to get the details, you can use:

$cat = get_category( $cat_id )


share|improve this answer

I've also got it from the following :

$cur_cat_id = get_cat_id(single_cat_title("",false));
$category = get_category($cur_cat_id);

But I guess s-ha-dum's solutions is better.

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.