Ashley Cameron Design

Ashley Cameron Design

Shop the Creative Design Market

Good evening

Show all terms of a custom taxonomy with hierarchy

This post was last updated: Sep 12, 2022
PHPSnippetsWordPress

About a 1 minute read

"The art of living… is neither careless drifting on the one hand nor fearful clinging to the past on the other. It consists in being sensitive to each moment, in regarding it as utterly new and unique, in having the mind open and wholly receptive."

Alan Watts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php $parentTerms = get_terms('specifications', array('hide_empty' =--> 0, 'parent' =&gt;0));
foreach($parentTerms as $parentTerm) : ?>
<ul>
    <li><a href="&lt;?php echo get_term_link( $parentTerm-&gt;slug, $parentTerm-&gt;taxonomy ); ?&gt;"><!--?php echo $parentTerm--->name; ?&gt;</a>
<ul class="megaSubCat"><!--?php
            $childargs = array(
               'hierarchical' =--> 1, 'show_option_none' =&gt; '', 'hide_empty' =&gt; false, 'parent' =&gt; $parentTerm-&gt;term_id, 'taxonomy' =&gt; 'specifications' ); $children = get_categories($childargs); foreach ($children as $child): ?&gt;
    <li><a href="&lt;?php echo get_term_link( $child-&gt;slug, $child-&gt;taxonomy );?&gt;"><!--?php echo $child--->name;?&gt;</a></li>
<!--?php
            endforeach;
            ?--></ul>
</li>
</ul>
<pre><!--?php endforeach; ?-->