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

My post has only one category. The following code:

$categories = get_the_category();

gives me this result:

    [0] => stdClass Object
            [term_id] => 22
            [name] => Style Guide
            [slug] => style-guide
            [term_group] => 0
            [term_taxonomy_id] => 22
            [taxonomy] => category
            [description] => 
            [parent] => 0
            [count] => 2
            [object_id] => 391
            [cat_ID] => 22
            [category_count] => 2
            [category_description] => 
            [cat_name] => Style Guide
            [category_nicename] => style-guide
            [category_parent] => 0


Why is it double up?

share|improve this question
I only see one array element, what seems to be the issue? – mor7ifer Feb 27 '12 at 18:51
[count] => 2, [category_count] => 2 – Steven Feb 27 '12 at 18:55
up vote 4 down vote accepted

I'm guessing you're referring to the

[category_count] => 2

when you say "saying that I have two categories"?

If so, you should understand that category_count is not the number of cateogries that this post has, but rather it is 'the number of uses of this category (also stored as 'count')' - see get_the_category function reference. The fact that there is only one array element in the returned object indicates that there is only 1 category assigned to this post.


... will give you what you are looking for.

share|improve this answer
I like the way you think :D (though category_count is an object property, not an array element :P) – mor7ifer Feb 27 '12 at 18:57
Ah, that makes is a bit more clear.Better naming wouldn't hurt, e.g. usages. Thanks :) – Steven Feb 27 '12 at 19:06

$categories[$i]->count and $categories[$i]->category_count are the number of posts in the category, not the number of categories there are. count( $categories ) will give you the number of categories there are. Each array element represents a category.

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.