php - How to merge same name as one and store their value? -


during making team honor list facing problem.i using following codes show team names , number of seasons.

codes:

<?php $terms = wp_get_post_terms( $post->id, array('competition') ); $term_slugs = wp_list_pluck( $terms, 'slug' );   $args = array(   'post_type'  => 'football_league',   'tax_query' => array(             array(             'taxonomy' => 'competition',             'field' => 'slug',             'terms' => $term_slugs             )         ),  );        $fixture_query = null;     $fixture_query = new wp_query($args); ?>   <?php while ( $fixture_query->have_posts() ) : $fixture_query->the_post();              $champion_team = get_post_meta( get_the_id(), 'football_league_team_name', true );             echo $champion_team;              $terms_session = get_the_terms( $post->id , 'session' ); ?>            <?php              foreach ($terms_session $object) {?>            <li> <?php echo  $object->name; ?></li>           <?php }            ?>         <?php endwhile; ?>    <?php wp_reset_postdata(); ?>  

this codes output follows:

    barcelona
  • 2017-18
    barcelona
  • 2016-17
    real madrid
  • 2014-15

but want output follows:

    barcelona (2 times)
  • 2017-18
  • 2016-17
    real madrid (1 time)
  • 2014-15


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -