最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Group the events post in month+year format?

programmeradmin2浏览0评论

How to print upcoming events in the below format.

June 2019

Trala Lala Wala

May 2019

Trala Lala Wala

my args array is

 $arg = array(
                'post_type' => 'events-promotion',
                'posts_per_page' => -1,
                'post_status' => 'publish',
                'meta_key'=>'wpcf-event-date',
                'meta_value' => $curdate,
                'meta_compare' => '>=',
                'orderby'=>'meta_value',
                'order' => 'DESC',
    );

How to print upcoming events in the below format.

June 2019

Trala Lala Wala

May 2019

Trala Lala Wala

my args array is

 $arg = array(
                'post_type' => 'events-promotion',
                'posts_per_page' => -1,
                'post_status' => 'publish',
                'meta_key'=>'wpcf-event-date',
                'meta_value' => $curdate,
                'meta_compare' => '>=',
                'orderby'=>'meta_value',
                'order' => 'DESC',
    );
Share Improve this question edited Nov 12, 2019 at 11:32 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Nov 12, 2019 at 6:16 soofzsoofz 14 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

$arg = array(
            'post_type' => 'events-promotion',
            'posts_per_page' => -1,
            'post_status' => 'publish',
            'meta_key'=>'wpcf-event-date',
            'meta_value' => $curdate,
            'meta_compare' => '>=',
            'orderby'=>'meta_value',
            'order' => 'DESC',
);

$the_query2 = new WP_Query( $arg );
$arr=array();
if ( $the_query2->have_posts() ) :
while ( $the_query2->have_posts() ) : $the_query2->the_post();
$eveid2 = get_the_ID();
$evedate2 = get_post_meta($eveid2,'wpcf-event-date',true);
$evedt = date('d/m/Y', $evedate2);
$pdate = date_i18n( 'M j, Y', $evedate2 );
$year=date('Y', $evedate2);
$month=date('m', $evedate2);

$arr[$year][$month][]=get_the_ID();
   endwhile;
endif; 

foreach($arr as $index => $ar1){


    foreach($ar1 as $index =>$ar2){

        ?>
        <div class="col-sm-12">

        <?php

          $monthName = date('F', mktime(0, 0, 0, $index, 10)); // March
          echo '<h4>'.$monthName.'</h4>';
        foreach($ar2 as $ar3){

    $evelink = get_post_meta($ar3,'wpcf-event-link',true);
$evetitle = get_the_title($ar3);
$image = wp_get_attachment_image_src( get_post_thumbnail_id($ar3), 'single-post-thumbnail' );
 $evedate2 = get_post_meta($ar3,'wpcf-event-date',true);
$evedt = date('d/m/Y', $evedate2);
    ?>
    <div class="col-sm-4 plcholder">
  <div class="imgpart"><img src="<?php echo $image[0]?>"></div>
  <div class="evepart">
      <p><?php echo $evedt;?></p>
      <h6><?php echo $evetitle;?></h6>
  </div>
  </div>
    <?php
    }
    ?></div><?php
    }
}
?>

发布评论

评论列表(0)

  1. 暂无评论