Hi
I have a CT of Staff Department and CP of Staff.
I want to display all the posts listed by e.g:
Parent Category
- Child Category
- Post Name
- Post Name
- Post Name
- Child Category
- Post Name
- Post Name
Parent Category
- Child Category
- Post Name
- Post Name
- Post Name
- Child Category
- Post Name
- Post Name
I have the following code which works fine but only displays the posts under the category it is listed in.
function dc_show_staff(){
$terms = get_terms( 'staff_department' );
foreach ( $terms as $term ) {
$term_name = $term->name;
$args = array(
'orderby' => 'title',
'order' => 'ASC',
'post_per_page' => -1,
'hide_empty' => 0,
'tax_query' => array(
array(
'taxonomy' => 'staff_department' ,
'field' => 'slug',
'terms' => $term->slug,
'include_children' => 0
)),
);
$term_posts = new WP_Query( $args );
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;
}
How would I modify this to display the Parent Category as a header for each child category? Thanks!