我正在使用自定义帖子类型构建一个事件插件。我运行了一个循环,它将使用一个短代码显示页面上的所有事件。我的问题是如何设置它,以便它按元数据库中设置的月份对事件进行分组_eDate
并将该组放在一个标题下。例如,7月的所有事件将显示在7月h1标记下。
以下是我当前使用的循环:
function events_list_shortcode() {
// Query Post Type
$args = array(
\'post_type\' => \'events\',
\'post_status\' => \'publish\'
);
$i = 0;
$the_query = new WP_Query($args);
// Build It
if ($the_query->have_posts()) :
?>
<div id="event-list">
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<div class="row">
<div class="event-image alignleft">
<a href="<?php echo get_permalink(get_the_ID()); ?>">
<?php
if (has_post_thumbnail()) {
the_post_thumbnail(\'thumbnail\');
}
?>
</a>
</div>
<div class="event-content alignleft">
<h3><a href="<?php echo get_permalink(get_the_ID()); ?>"><?php the_title(); ?></a></h3>
<?php
$eventDate = strtotime(get_post_meta(get_the_ID(), \'_eDate\', true));
if (!empty($eventDate)) {
?>
<div class="event-date">
<?php echo date(\'F - j\', $eventDate); ?>
</div>
<?php } ?>
<?php
$eventTime = strtotime(get_post_meta(get_the_ID(), \'_eTime\', true));
if (!empty($eventDate)) {
?>
<div class="event-time">
<?php echo date(\'g:i A\', $eventTime); ?>
</div>
<?php } ?>
<?php
$eventPrice = get_post_meta(get_the_ID(), \'_ePrice\', true);
if (!empty($eventPrice)) {
?>
<div class="event-price">
<?php echo $eventPrice; ?>
</div>
<?php } ?>
<br/>
<a href="<?php echo get_permalink(get_the_ID()); ?>">More Information</a>
</div>
<div class="event-buy alignleft">
<?php
$eventBuy = get_post_meta(get_the_ID(), \'_eBuy\', true);
if (!empty($eventDate)) {
?>
<div class="event-buy">
<a class="buy-btn btn" href="<?php echo $eventBuy ?>" target="_blank">Buy Online</a>
</div>
<?php } ?>
</div>
</div>
</div>
<?php wp_reset_postdata(); ?>
<?php
endwhile;
endif;
}