I have a CPT named “football_fixture”.This CPT has taxonomy named “competition”, and this taxonomy has different terms , laliga, eng.
I want to show my post as follow:
laliga:
List of all posts published including above terms.
eng:
List of all posts published including above terms.
I am using following codes but it show the content as showed in the image1.
I want the post like image 2: image1: Here is the codes I am using:
<?php
/**
* Template Name: Fixture
* Description: The template for displaying all posts and attachments
*/
?>
<?php get_header(); ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$term_id = get_queried_object()->term_id;
$args = array( 'post_type' => 'football_fixture',
'paged' => $paged,
);
query_posts( $args );
?>
<?php if(have_posts()): ?>
<div class="<?php echo $col; ?>">
<?php while(have_posts()): ?>
<?php 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="fixture-info clearfix">
<p class="pull-left match-date"><?php echo ($date); ?></p>
<p class="pull-left match-date">
<?php
$terms = get_the_terms( get_the_ID(), 'competition' ); // 'taxonomy' field doesn't store term IDs in the custom fields, instead, it sets post terms
if ( !empty( $terms ) ) {
$content = '<ul>';
foreach ( $terms as $term ) {
$content .= sprintf(
'<li><a href="%s" title="%s">%s</a></li>',
get_term_link( $term, 'tax_slug' ),
$term->name,
$term->name
);
}
$content .= '</ul>';
echo $content;
}
?>
</p>
</div>
<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();
?>
</div>
<?php endif; ?>
<?php get_footer(); ?>