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 am coding a pretty complex wordpress site (at least, taxonomically speaking), and i need to display a list of categories, children of a parent category, but I am struggling with getting the code to do this.

I tried doing something like:

$cat = get_query_var('cat');
$categories=  get_categories('hide_empty=0&parent=1&child_of='.$cat);
foreach ($categories as $category) {
$mycat .= $category->cat_name;
echo $mycat;

But i don't seem to get the correct output.

Do you have any idea? Thx!

share|improve this question
up vote 2 down vote accepted

Why are you using the parameter parent=1? If you remove this parameter it should work.

If you want children and grandchildren, you should use:

$categories =  get_categories('hide_empty=0&child_of='.$cat);

If you want only direct children, you should use:

$categories=  get_categories('hide_empty=0&parent='.$cat);

Also note that you are echoing $mycat inside the loop, and you are joining the multiple categories in this var, so the categories should appear repeated...

share|improve this answer
mmh right... and how would i make it not duplicated? – alemur Dec 15 '12 at 0:27
just put the echo $mycat outside the loop, so that you're writing the list of categories only in the end – dbeja Dec 15 '12 at 0:47

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.