I don’t realy understand how to use get_terms(), and maybe, get_term_children() for deal with this.
I believe you’re missing 3 important pieces of information:
- terms that have no parent have a parent ID of
0
- you can ignore
get_term_children
, just use theparent
parameter ofget_terms
- for this to work more than one or two levels deep you will need to put this in a recursive function or you’ll just end up with tonnes of nested loops
get_terms
takes the same arguments as WP_Term_Query
, I strongly recommend reading through the available arguments on the official documentation:
https://developer.wordpress.org/reference/classes/wp_term_query/__construct/
Likewise, all of this would have been explained with examples in the comments for the official get_terms
documentation page:
https://developer.wordpress.org/reference/functions/get_terms/