In your custom templates, First you have to fetch all terms for your custom post type.
You can use get_terms to retrive terms in taxonomy
If you are using wordpress prior to 4.5
$terms = get_terms( 'competition' , array(
'hide_empty' => false
) );
OR if you are using wordpress prior to 4.5.0 or later
$terms = get_terms( array(
'taxonomy' => 'competition',
'hide_empty' => false,
) );
Next Build Term name lists:
$termNames = array();
$count = count( $terms );
if ( $count > 0 ) {
foreach ( $terms as $term ) {
$termNames[] = $term->name;
}
}
Next loop trough each terms and query posts for the current terms & then run the loop:
foreach($termNames as $termName) :
$args = array(
'post_type' => 'football_fixture',
'competition' => $termName,
'order' => 'ASC',
);
query_posts( $args );
if(have_posts()): ?>
<div class="<?php echo $col; ?>">
<h2><?php echo $termName; ?></h2>
<?php while(have_posts()): the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
$id = get_the_ID();
$date = rwmb_meta( 'pb_match_date','', $post->ID);
$time = rwmb_meta( 'pb_match_time','', $post->ID );
$competition = rwmb_meta( 'pb_match_competition_cats','', $post->ID );
$team_a = get_post_meta( $post->ID, 'match_details_home_team', true );
$team_b = get_post_meta( $post->ID, 'match_details_away_team', true );
?>
<div class="fixture-item">
<div class="row">
<div class="col-xs-4">
<div class="media">
<div class="media-body">
<h4><?php echo $team_a; ?></h4>
</div>
</div>
</div>
<div class="col-xs-4 match-time">
<i class="fa fa-clock-o"></i> <?php echo $time; ?>
</div>
<div class="col-xs-4">
<div class="media">
<div class="media-body">
<h4 class="pull-right"><?php echo $team_b; ?></h4>
</div>
</div>
</div>
</div>
</div>
</div><!--/#post-->
<?php endwhile; ?>
<?php
wp_reset_query();
?>