我创建了一个名为"显示"的新wpost类型,并为其分配了一个ACF日期字段。在成功显示帖子及其详细信息的同时 - 我没有按日期(ACF日期,而不是帖子创建日期)对它们进行排序。
这是我的代码:http://codeshare.io/rpZIL
<ul id="shows-container">
<?php
$today = current_time('Ymd');
$args = array(
'post_type' => 'shows',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'show_date',
'compare' => '>=',
'value' => $today,
)
),
'meta_key' => 'show_date',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
//the query
$theshows = new WP_Query($args);
if($theshows->have_posts()):
while($theshows->have_posts()):
$theshows->the_post();
$showdate = get_field('show_date');
$showday = get_field('show_day');
$showhour = get_field('show_time');
$showloc = get_field('show_location');
$showphone = get_field('show_phone');
$showtickets = get_field('show_tickets');
?>
<li class="show-box">
<h3><?php the_title() ?></h3>
<div class="show-time">
<span class="show-date"><? echo $showdate ?></span>-<span class="show-day"><? echo $showday ?></span>-<span class="show-hour"><? echo $showhour ?></span>
</div>
<p class="show-address"><? echo $showloc ?></p>
<p class="show-phone"><? echo $showphone ?></p>
<a href="<? echo $showtickets ?>"><span><?php _e('Tickets','doliart');?></span></a>
</li>
<?php
endwhile;
else:
?>
Oops, there are no posts.
<?php
endif;
wp_reset_query(); ?>
</ul>