If you’d like to group posts by meta value, try the following code:
$query = new WP_Query(
array (
'orderby' => 'meta_value',
'meta_key' => 'coach_location',
'order' => 'ASC'
)
);
Please refer to the Codex.
Let’s say you’d like to print the Coach Location for each group, the sample code should be:
$last_location = '';
while ( $query->have_posts() ) : $query->the_post();
$location = get_post_meta( $post->ID, 'coach_location', true );
if ( $last_location != $location ){
echo $location;
$last_location = $location;
}
// echo the reset content
endwhile;
wp_reset_postdata();