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

Right, hopefully a nice and simple one... I'm on a category page with the id of 4, I want to get the category object back so I can interogate a few values.

I've had a good old look in the WP codex with little success, remember I don't want to get the categories from a post, I want the category object from the current category.

Many thanks, Ben :-)

share|improve this question
You should vote up Fernandos answer and check it as the sollution – kaiser Jan 25 '11 at 16:36
up vote 5 down vote accepted

To get the category object use get_category (codex). It's easy if you know the name, slug or ID, but if you don't you could use is_category to check on which category you are and pass the ID to get_category.

share|improve this answer
This doesn't actually make sense. In fact, this is the only response that ISN'T a correct answer. The OP wanted a way to get the cat object. is_category doesn't "check on which category you are" - it tells you IF you're on a category page. If you have the ID, then yeah you can use get_category(), but I'm assuming here that the OP was using ID=4 as an arbitrary example, but actually wouldn't know beforehand the ID of the cat he wanted to query. – Tom Auger Jun 2 '11 at 0:02
This isn't a correct answer...! As you wrot Tom. – jepser May 22 '12 at 18:41

Damn, so I did find the answer I was looking for:

$thisCat = get_category(get_query_var('cat'),false);

Never mind :-)

share|improve this answer

$wp_query->get_queried_object() is a very versatile function. It will return the current category, tag, custom taxonomy term, author, page or post, depending on the page/archive you are viewing. Especially handy if you want to simplify your archive headings.

share|improve this answer

I'd personally get into a habit of calling get_term or get_terms, as the category functions are only wrapper functions that in turn call get_term(s) anyway.

$queried_category = get_term( get_query_var('cat'), 'category' ); 

// echo $queried_category->term_id; // The category ID
// echo $queried_category->slug; // The category slug
// echo $queried_category->name; // The category name 
// echo $queried_category->description; // The category description 

Familiaring yourself with the term functions will make dealing with custom taxonomies a little easier, because you'll be calling on these functions in such cases.


And a function that i don't see used a great deal, but can be really handy.
Which provides a means of fetching a term object based on name, slug or ID.

share|improve this answer

An interesting case wherein one of many category archive pages included in a custom menu returned an empty array for


required me to run through all the different ways to skin a cat (no pun intended).

is_category() RETURNS true
get_the_category() RETURNS an empty array
the_category() RETURNS NULL

The final answer ended up being Ben Everard's

 get_category(get_query_var('cat'), false) RETURNS the correct WPCategory object


share|improve this answer
actually, @JanFabry's answer is the one here which should be marked "correct" - get_queried_object(), much simpler, and the preferred method. – Milo Jan 14 '13 at 19:38

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.