I want to get second level terms of a specific parent (first-level) term in a custom taxonomy. Sounds complicated but would be useful.
Term 1
SubTerm-1.1
SubTerm-1.2
SubTerm-1.2.1
Term 2
SubTerm-2.1
Say, if SubTerm->parent
is Term 1’s id, then i want to output SubTerm 1.1 and 1.2 but not 1.2.1.
wp_list_categories(array('depth' => 2, 'taxonomy' => 'customtax'));
is not i’m looking for as it lists terms with their links, which i dont want to, and there is no filtering option by SubTerm->parent
id.
So any idea?
You can use PHP’s
array_filter
to process the results of a taxonomy query function that returns its results, and then display them. Something like:At this point you can render
$second_level
to output in whatever format you want.NB. If this is often used on a busy side should avoid all those extra
get_term
calls by reading from the$whole_tax
array assuming the documentation’s statement thatget_term
always hits the database when passed an id.