Title: petedc's Replies | WordPress.org

---

# petedc

  [  ](https://wordpress.org/support/users/petedc/)

 *   [Profile](https://wordpress.org/support/users/petedc/)
 *   [Topics Started](https://wordpress.org/support/users/petedc/topics/)
 *   [Replies Created](https://wordpress.org/support/users/petedc/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/petedc/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/petedc/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/petedc/engagements/)
 *   [Favorites](https://wordpress.org/support/users/petedc/favorites/)

 Search replies:

## Forum Replies Created

Viewing 1 replies (of 1 total)

 *   Forum: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
   
   In reply to: [Listing Custom Posts in Custom Taxonomy](https://wordpress.org/support/topic/listing-custom-posts-in-custom-taxonomy/)
 *  Thread Starter [petedc](https://wordpress.org/support/users/petedc/)
 * (@petedc)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/listing-custom-posts-in-custom-taxonomy/#post-5246599)
 * Awesome, thanks for pointing me in the right direction! Final code if it helps
   anyone:
 *     ```
       function dc_show_staff(){
   
           $parent_terms = get_terms( 'staff_department', array( 'parent' => 0 ));
   
           foreach ( $parent_terms as $parent_term ) {
   
               $output .= '<h3>'.$parent_term->name.'</h3>';
   
               $child_terms = get_terms( 'staff_department', array( 'parent' => $parent_term->term_id ));
   
               foreach ( $child_terms as $child_term ) {
                   $args = array(
                           'orderby'   => 'title',
                           'order'     => 'ASC',
                           'post_per_page' => -1,
                           'hide_empty' => 0,
                           'tax_query'   => array(
                                           array(
                                             'taxonomy' => 'staff_department' ,
                                             'field' => 'slug',
                                             'terms' => $child_term->slug,
                                             'include_children' => 1
                                           )),
                           );       
   
                   $term_posts = new WP_Query( $args );
                   $term_name = $child_term->name;
   
                   while( $term_posts->have_posts() ) {
                       $term_posts->the_post();
   
                       if ( $term_name ) {
                           $output .= '<h3>'.$term_name.'</h3><div class="row">';
                           $term_name = '';
                       }
   
                       $output .= '<div class="col-sm-2 staff-item">';
                       $output .= '<a href="' . get_permalink() . '">' .get_the_post_thumbnail($post->ID , 'thumbnail', 'class=img img-circle img-responsive'). '</a>';
                       $output .= '<a href="'.get_permalink().'">'.get_the_title().'</a>';
                       $output .= get_post_meta($post->ID, 'job_title', true);
                       $output .= '</div>';
                   }
   
                   if ( !$term_name ) {
                     $output .= '</div>';
                   }
               }
           }
           wp_reset_postdata();
           wp_reset_query();
   
           return $output;
       }
       ```
   

Viewing 1 replies (of 1 total)