关于 php:如何在自定义字段中按日期排列 WordPress 帖子?

How to arrange WordPress posts by date in a custom field?

关于我正在为客户开发的自定义 wordpress 主题 (http://garethstewart.co.uk) 我有一个自定义帖子类型的事件列表。我希望能够按时间顺序排列它们。这是我必须呈现日期的代码:

1
2
3
4
5
6
7
8
9
10
11
12
<?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) : ?>
   
       
            <i class="icon inline-block mb30 fade-0-4 fa fa-calendar-o" style="font-size: 38px !important;">
            <h4 class="uppercase bold"><?php the_field('date'); ?></h4>
            <h5><?php the_field('description'); ?></h5>
       
   
<?php endif; ?>

非常感谢任何帮助。

谢谢,
杰米


在你的论点中使用这个:

1
2
3
4
5
6
7
8
$args = array(
        'post_type'=> 'event',
        'posts_per_page' => 9,
        'orderby' => 'meta_value',
        'meta_key' => 'date',
        'meta_type' => 'DATE',
        'order' => 'ASC',
    )