Ashley Cameron Design

Ashley Cameron Design

Shop the Creative Design Market

Good afternoon

Show all terms of a custom taxonomy with hierarchy

This post was last updated: Sep 12, 2022
PHPSnippetsWordPress

About a 1 minute read

"Not until we are lost do we begin to understand ourselves."

Henry David Thoreau

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; ?-->