一种方法是在foreach中创建另一个get\\u类别($类别为$类别)
Example code
//preparing an array to hold later info
$grandchildren_ids = [];
//getting the child categories of parent 72
$args = array(
\'orderby\' => \'name\',
\'parent\' => 72,
\'taxonomy\' => \'category\',
\'hide_empty\' => 0
);
$categories = get_categories($args);
foreach ( $categories as $category ) {
//setting up the args where the parents are the child categories
$grandchildrenargs=array(
\'parent\' => $category->term_id,
\'taxonomy\' => \'category\',
\'hide_empty\' => 0
);
$grandchildrencategories = get_categories($grandchildrenargs);
foreach ( $grandchildrencategories as $grandchildrencategory ) {
//getting the grandchildren ids or whatever else is needed and populating the array
$grandchildren_ids[] = $grandchildrencategory->term_id;
}
}
var_dump($grandchildren_ids);