please, can any one help me , I am new in wordpress world. how to get sub categories by parent category id in wordpress?
2 Answers
15
votes
You need to use get_terms($taxonomies, $args);
$parent_term_id = 4; // term id of parent term (edited missing semi colon)
$taxonomies = array(
'category',
);
$args = array(
'parent' => $parent_term_id,
// 'child_of' => $parent_term_id,
);
$terms = get_terms($taxonomies, $args);
You could also use 'child_of'
instead;
Note: the difference between child_of and parent is that where parent only gets direct children of the parent term (ie: 1 level down), child_of gets all descendants (as many levels as are available)
Codex: get_terms