I need to foreach loop the first parent taxonomy and its children ONLY.
I’ve managed to get all the parents and their children to loop out, but can’t restrict it to just the first set, in this case the summer taxonomies only.
<?php
// Taxonomy
$taxonomyName = "classification";
// Parent Taxonomy
$parent_terms = get_terms(
$taxonomyName, array(
'parent' => 0,
'orderby' => 'slug',
'hide_empty' => true
));
foreach ( $parent_terms as $parent_term ) {
echo '<a class="category-tile" href="' . get_term_link( $parent_term ) . '">' . $parent_term->name . '</a>';
// Child Taxonomies
$child_terms = get_terms(
$taxonomyName, array(
'parent' => $parent_term->term_id,
'orderby' => 'ASC',
'hide_empty' => true
));
foreach ($child_terms as $child_term) {
echo '<a class="category-tile" href="' . get_term_link( $child_term ) . '">' . $child_term->name . '</a>';
}
} ?>
See screen grab of the results and what i’d like to exclude.