[英]How to arrange Wordpress posts by date in a custom field?
on a custom wordpress theme I am developing for a client ( http://garethstewart.co.uk ) I have a list of Events which are a custom post type. 在我为客户开发的自定义wordpress主题上( http://garethstewart.co.uk ),我有一个自定义帖子类型的事件列表。 I want to be able to order them chronologically. 我希望能够按时间顺序订购它们。 Here is the code I have to render out the dates: 这是我必须绘制日期的代码:
<?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; ?>
Any help is really appreciated. 任何帮助都非常感谢。
Thanks, Jamie 谢谢杰米
Use this in your arguments: 在您的参数中使用:
$args = array(
'post_type'=> 'event',
'posts_per_page' => 9,
'orderby' => 'meta_value',
'meta_key' => 'date',
'meta_type' => 'DATE',
'order' => 'ASC',
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.