$terms = get_terms( array(
'taxonomy' => 'category',
'hide_empty' => true,
'orderby'=> 'name',
'order'=>'ASC'
));
foreach( $terms as $term){
$termChildren = get_term_children($term->term_id, 'category');
$args = array('post_type' => 'course',
'post_status' => 'publish',
'posts_per_page' => '-1',
'orderby' => 'ID',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'course_categories',
'field' => 'slug',
'terms' => $term->slug
),
)
);
$query = new WP_Query($args);
while ($query->have_posts()): $query->the_post();
the_title(); the_content();
endwhile;
}