I have many categories of this type:

Category 1> Subcategory 1> Subcategory 1

Category 2> Subcategory 1> Subcategory 1

How can I get an array with the ID of subcategories only? I tried to specify parent = 0, but then just because I only have Parental main categories and displays.

$categories = get_terms( 'category', array('order'=> 'DESC', 'fields' => 'ids', 'hide_empty' => 1) ); foreach($categories as $category) { echo $category->term_id; } 

    1 answer 1

    Try this:

     $all_categories = get_terms(array( 'taxonomy' => 'category', 'hide_empty' => 1, )); $third_level = array_filter($all_categories, function ($t) { return $t->parent != 0 && get_term($t->parent, 'category')->parent != 0; }); $third_level_ids = array_map(function ($t) { return $t->term_id; }, $third_level); 
    • Thank you so much, what you need! - akasergej