Custom post type with taxonomy children

Through landing we are showing categories. Clicking on any category show child sub categories. But this shows child of child as well. following is our code to retrieve sub categories.

$terms = get_terms( 'msproduct' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
    echo '<ul>';
    foreach ( $terms as $term ) {
        echo '<li>' . $term->name . '</li>';
    }
    echo '</ul>';
}

please advice. My category structure is following

Commercial Ovan
- 900 Series
-- Product 1
-- Product 2
- 700 Series
-- Product 1
- 600 Series
-- Product 1
-- Product 2
-- Product 3
-- Product 4

Read more here: Custom post type with taxonomy children

Leave a Reply

Your email address will not be published. Required fields are marked *