<ul>
<li>
Родитель
<ul>
<li>дети</li>
<li>дети</li>
</ul>
</li>
</ul>
<?php
$args = array( 'taxonomy' => 'projectscat', 'hide_empty' => true, 'parent' => 0 );
$product_categories = get_terms('projectscat', $args);
foreach ($product_categories as $term) :
echo '<li><a href="/your-category-base-url/' . $term->slug . '" title="' . sprintf(__('Category %s', 'zigcy-lite'), $term->name) . '">' . $term->name . ' ('.$term->count.')</a></li>';
?>
<li><a href="<?php $term->slug ?>">
<ul>
<?php $term->name . $term->count ?>
<?php
$termChild = $term->term_id;
$termChildArray = get_terms([
'taxanomy' => 'projectscat',
'child_of' => $termChild,
'hide_empty' => false,
]);
foreach($termChildArray as $termChildArrayKey) :
?>
<li>
<?php echo $termChildArrayKey->name; ?>
</li>
<?php endforeach; ?>
</ul>
</a></li>
<?php
endforeach;
?>
public static function get_taxonomy_hierarchy( $taxonomy, $parent = 0 ) {
$taxonomy = is_array( $taxonomy ) ? array_shift( $taxonomy ) : $taxonomy;
$terms = get_terms( $taxonomy, array( 'parent' => $parent ,'hide_empty'=>0) );
$children = array();
foreach ( $terms as $term ){
$term->children = self::get_taxonomy_hierarchy( $taxonomy, $term->term_id );
$children[ $term->term_id ] = $term;
}
return $children;
}
public function get_taxonomy_hierarchy_multiple( $taxonomies, $parent = 0 ) {
if ( ! is_array( $taxonomies ) ) {
$taxonomies = array( $taxonomies );
}
$results = array();
foreach( $taxonomies as $taxonomy ){
$terms = get_taxonomy_hierarchy( $taxonomy, $parent );
if ( $terms ) {
$results[ $taxonomy ] = $terms;
}
}
return $results;
}
<ul>
<?php $hiterms = get_terms("название ваше таксономии", array("orderby" => "slug", "parent" => 0)); ?>
<?php foreach($hiterms as $key => $hiterm) : ?>
<li>
<?php echo $hiterm->name; ?>
<?php $loterms = get_terms("my_tax", array("orderby" => "slug", "parent" => $hiterm->term_id)); ?>
<?php if($loterms) : ?>
<ul>
<?php foreach($loterms as $key => $loterm) : ?>
<li><?php echo $loterm->name; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>