Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I believe I could do this with either get_categories() or wp_list_categories() and passing a 'child_of' parameter, for example, but that would return a much larger dataset than I need.

Is there a direct call that returns the child ids for any category as a simple list (1,2,3,5, etc)?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Try this:

get_terms( 'category', "child_of=$parent&fields=ids" );
// should return an array containing the ID's of children of term $parent
share|improve this answer
    
@goldenapples: Is this correct? var_dump(get_terms('category', "child_of=1&fields=ids" ))? (returns array(0) { }) –  Scott B Jan 12 '11 at 17:58
    
It looks right to me, are there children to fetch? And are they non-empty? Look at the available arguments here: core.trac.wordpress.org/browser/tags/3.0.4/wp-includes/… –  goldenapples Jan 12 '11 at 18:05
    
just add 'show_empty=true' to the second param I think. –  sanchothefat Jan 12 '11 at 18:07
    
Actually, I think the problem is that I'm seeding $parent with the category id, not the term_id. But shouldn't they be the same? I'm trying to list all children of the uncategorized category, which is id tag_ID 1. –  Scott B Jan 12 '11 at 18:07
    
How about get_term_children(1,'category') ? –  Scott B Jan 12 '11 at 18:21

Your Answer

 
discard

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.