get sub categories of several categories with get_categories()

Is there a way to get all sub categories of several categories? something like:

get_categories( array( 'child_of'=>array(10,3,8) );

Related posts

1 comment

  1. It’s not possible, wordpress just accepts one integer in all it’s functions that get categories children. You’ll have to get their children separately:

    $terms = array();
    $taxonomy = 'category';
    $parents = array(10, 3, 8);
    foreach ($parents as $parent) {
        $terms = array_merge($terms, get_categories(array('child_of'=> $parent)));
    }
    
    foreach ($terms as $term) {
        // your code here
    }
    

    Hope it helps!

Comments are closed.