petedc
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Hacks
In reply to: Listing Custom Posts in Custom TaxonomyAwesome, 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)