• I want to display only 1st level of sub taxonomies, below is my code,it’s just not working, can anyone please tell whats wrong with my code?? Many thanks.

    <?php
    $term_id = 31;
    $taxonomy_name = 'kosher_category';
    $termchildren = get_term_children( $term_id, $taxonomy_name );
    
    echo '<ul>';
    foreach ( $termchildren as $child ) {
    	$term = get_term_by( 'id', $child, $taxonomy_name );
    	echo '<li><a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $term->name . '</a></li>';
    }
    echo '</ul>';
    ?>
Viewing 1 replies (of 1 total)
  • Thread Starter lukelee

    (@lukelee)

    I have changed the code a bit. But still couldn’t get it work.

    <?php
    
    $term_id = 31;
    $taxonomy_name = 'kosher_category';
    
    $args = array('child_of' => $term_id, 'parent' => $term_id);
    $termchildren = get_terms($taxonomy_name, $args );
    
    echo '<ul>';
    foreach ( $termchildren as $child ) {
    	$term = get_term_by( 'id', $child, $taxonomy_name );
    	echo '<li><a href="#">' . $term->name . '</a></li>';
    }
    echo '</ul>';
    ?>

Viewing 1 replies (of 1 total)
  • The topic ‘List only 1st level of sub taxonomies’ is closed to new replies.