Есть иерархия вложенностей термов таксономии. Она может быть разной от 2 до 5 уровней вложенности. У меня есть функция которая принимает ID терма родителя и название таксономии.
Вот эта функция:
function hierarchyTerms( $termID, $taxonomy, )
{
$terms_children = get_term_children( $termID, $taxonomy );
if( ! is_wp_error( $terms_children ) && ! empty( $terms_children ) ) {
$output = '';
$output .= '<ul>';
foreach ( $terms_children as $child_id )
{
$output .= '<li>'. get_term( $child_id )->name. '';
$output .= hierarchyTerms( $child_id, $taxonomy );
$output .= '</li>';
}
$output .= '</ul>';
return $output;
}
}
Мне нужно чтобы на выходе сформировался следующая структура HTML:
<ul>
<li>
Category 1
<ul>
<li>Cat 1.1</li>
<li>Cat 1.2</li>
</ul>
</li>
<li>
Category 2
<ul>
<li>Cat 2.1</li>
</ul>
</li>
</ul>
Но у меня в конце появляется дубляж термов. Видать это связано с рекурсией и областью видимости.