Customize Output of Get_Terms and Show Children

I’ve always wondered how to do this, and now I have an example on hand that I can refer to in the future. Comes in handy if you’re using custom navigation / filters with categories or terms.

$tax ='taxonomy';
        $args = array(
          'taxonomy' => $tax,
          'hide_empty' => false,
          'parent' => 0,
          );
    $toplv_term_query = new WP_Term_Query($args);
        foreach($toplv_term_query->get_terms() as $toplv_term){
             $args = array(
               'taxonomy' => $tax,
               'hide_empty' => false,
               'parent' => $toplv_term->term_id,
              );
          $secondlv_term_query = new WP_Term_Query($args);
              foreach($secondlv_term_query->get_terms() as $secondlv_term){
                   $secondlv_term->term_id;

             }
        }

Sourced here.

Leave a Reply

Posted in php
katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.

%d bloggers like this: