如何根据日期在自定义字段中安排Wordpress帖子?
问题描述:
关于自定义WordPress主题我正在为客户开发(http://garethstewart.co.uk)我有一个自定义帖子类型的事件列表。我希望能够按时间顺序排列。这里是我要呈现出的日期代码:如何根据日期在自定义字段中安排Wordpress帖子?
<?php $args = array('post_type' => 'event', 'posts_per_page' => 9);$loop = new WP_Query($args); while ($loop->have_posts()) : $loop->the_post(); ?>
<?php $event_date = get_field('date'); // Get the event's date ?>
<?php $today = date('F j, Y'); // Get today's date ?>
<?php if ($event_date >= $today) : ?>
<div class="text-center">
<div class="feature">
<i class="icon inline-block mb30 fade-0-4 fa fa-calendar-o" style="font-size: 38px !important;"></i>
<h4 class="uppercase bold"><?php the_field('date'); ?></h4>
<h5><?php the_field('description'); ?></h5>
</div>
</div>
<?php endif; ?>
任何帮助非常感谢。
感谢, 杰米
答
使用此在您的参数:
$args = array(
'post_type'=> 'event',
'posts_per_page' => 9,
'orderby' => 'meta_value',
'meta_key' => 'date',
'meta_type' => 'DATE',
'order' => 'ASC',
)
干杯,工作完美! – user3479267