I want to list categories belonging to a parent. The problem is using category id’s isn’t useful and makes things harder to understand.
Is there any easier way to list categories belonging to a parent, similar to the default way supplied in the WP codec?
<?php wp_list_categories('child_of=8'); ?> //what category is '8' ?!
<?php wp_list_categories('child_of=clients'); ?> //much nicer, but doesn't work
I would prefer to avoid using another query in the loop, but to make sense to other developers, I might have to.
You can get ID from slug quite easily:
Do you want all children on a set category then, as that’s essentially what the
child_of
parameter is for, getting all descendants of a term(category).If you want only terms that have a particular direct parent then you should instead be using
parent
.In regard to using an ID, this should work..
get_cat_ID docs.
Hope that helps..