Title: get_term_children return wrong ID&#8217;s
Last modified: August 21, 2019

---

# get_term_children return wrong ID’s

 *  [volodika](https://wordpress.org/support/users/volodika/)
 * (@volodika)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/get_term_children-return-wrong-ids/)
 * Hello, can someone help me
    Function get_term_children() return wrong ID’s
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fget_term_children-return-wrong-ids%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Ahir Hemant](https://wordpress.org/support/users/hemant-ahir/)
 * (@hemant-ahir)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/get_term_children-return-wrong-ids/#post-11854123)
 * Hi
 * Have you tried with static id like this:
 *     ```
       <?php
       $term_id = 27;
       $taxonomy_name = 'products';
       $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>';
       ?> 
       ```
   
 * Thanks
    Ahir
 *  [Ahir Hemant](https://wordpress.org/support/users/hemant-ahir/)
 * (@hemant-ahir)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/get_term_children-return-wrong-ids/#post-11854214)
 * if that not work for you then here is full code.
 *     ```
       $category = get_queried_object();
       $parent_term_id  = $category->term_id;
   
       //$termchildren = get_terms('category',array('child_of' => $parent_id));
       $taxonomies = array( 
           'taxonomy' => 'product-cat'
       );
       $args = array(
          // 'parent'         => $parent_term_id,
            'child_of'      => $parent_term_id
       ); 
       $terms = get_terms($taxonomies, $args);
       if (sizeof($terms)>0)
       {
       	echo '<ul class="b4u-inner-filters">';
       foreach ( $terms as $term ) {?>
       <li class="item-filter" id="<?php echo $term->term_id; ?>"><?php echo  $term->name; ?></li>
       <?php 
           }
       	echo '</ul>';
       }
       ```
   
 * Let me know how this help you.
 * Thanks
    Ahir
 *  Thread Starter [volodika](https://wordpress.org/support/users/volodika/)
 * (@volodika)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/get_term_children-return-wrong-ids/#post-11856288)
 * Unfortunatelly this code not helped
    Here dump of array of child category. Looks
   strange that id’s is equal to keys `array(5) { [0]=> int(0) [1]=> int(1) [2]=
   > int(2) [3]=> int(3) [4]=> int(4) } int(27) string(11) "product_cat"`

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘get_term_children return wrong ID’s’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [volodika](https://wordpress.org/support/users/volodika/)
 * Last activity: [6 years, 9 months ago](https://wordpress.org/support/topic/get_term_children-return-wrong-ids/#post-11856288)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
