What’s going on?
- During the first execution, we use
get_terms()to gather all terms that do not have any parents ( parent = 0 ).
- Then, we loop through those terms and get each of their children by calling the
get_taxonomy_hierarchy()on the terms.
- Every time we loop through a set of terms, we look for children that belong to each term.
- Finally, we return an array of terms with all it’s children stored within a new