I'm building a kind of selection tool. I have 9 parent taxonomies. Each one has some children and those all have posts.

I have the top level taxonomy displaying. However, I'm not quite sure how to get the child terms of each. My code is below.

 <div class="padded-panel">
                    $args = array(
                        'posts_per_page'   => -1,
                        'category_name'    => $term->slug,
                        'orderby'          => 'date',
                        'order'            => 'DESC',
                        'post_type'        => 'equipment',
                        'suppress_filters' => true,
                    $posts = get_posts( $args );
                    // echo "<pre>";
                    // echo  print_r($posts);
                    // echo "</pre>";

                <!-- <form action="page-estimator2.php" method="post"> -->
                    <select class="select-model" name="model">
                        <option value=""> Select a model </option>
                            foreach($posts as $post){ ?>
                            <?php $field = get_field("price_high", $post->ID); ?>
                            <option value="<?php echo $post->ID; ?>"> <?php echo $post->post_title; ?></option>
                        <?php } ?>
                            $post_id = $_POST['model']; 
                             echo "<h1>".$post_id."</h1>";
                <!-- </form> -->

1 Answer 1


For getting the child term of an parent you can use get_terms function

Here you can provide hide_empty as false ( this will list all term ) parent as the parent term id ( this will return the term related to that parent id

$tax_id = $term->term_id; 
$terms = get_terms( 'post_tag', array(
    'hide_empty' => false,
    'parent'     => $tax_id,
) );
  • What is the post_tag supposed to be? I've used the get_terms but for whatever reason it was pulling in EVERY term.
    – lz430
    Jul 15, 2016 at 15:30
  • post_tag is the the name of your taxonomy. You can replace that by any custom taxonomy
    – Aftab
    Jul 18, 2016 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.