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

so my category got slug 'aeroplanes' and I need to get category names from it, but I can't get it with

$category = get_the_category($post->ID); 
echo $category[0]->cat_name;

cause it takes all posts from default category with category slug 'category'. How can I do that if I got category slug 'aerpolanes'?

share|improve this question
possible duplicate of categories with different slug – Chip Bennett Oct 20 '11 at 19:47

See http://codex.wordpress.org/Function_Reference/get_term_by

The following code will work for your situation:

$cat = get_term_by( 'slug', 'aeroplane', 'category');
echo $cat->name;
share|improve this answer
Hello, it didn't help. It echoed nothing. + I got many subcategories in category that got slug aeroplane, and I need to echo those subcategory names. – Y2ok Oct 20 '11 at 18:12
@Y2ok - check the spelling in the answer by Russel Heimlich; make sure you use exactly the slug of your category ('aeroplanes'). you didn't directly ask for the child categories - please edit your question to make that clear. – Michael Oct 20 '11 at 18:52

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.