• I have three level categories in my WordPress site. It’s looks like:

    Parent A
    – Child A1
    – – Child child A11
    – – Child child A12
    – Child A2
    – – Child child A21
    – – Child child A22
    Parent B
    – Child B1
    – – Child child B11
    – – Child child B12
    – Child B2
    – – Child child B11
    – – Child child B12

    I have a code:

    <?php
            $termID = 3; // Parent A ID
            $taxonomyName = "products";
            $termchildren = get_term_children( $termID, $taxonomyName );
                echo'<div class="sub"> <div class="links">';
                  foreach ($termchildren as $child) {
                      $term = get_term_by( 'id', $child, $taxonomyName );
                      echo'<a href="#">' . $term->name . '</a>';}
                echo'</div> </div>';?>

    The result of the code is:

    Child A1
    Child child A11
    Child child A12
    Child A2
    Child child A21
    Child child A22

    How to get only the Child without Child Child?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to get term child?’ is closed to new replies.