2015-09-06 103 views
0

關於自定義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; ?> 

任何幫助非常感謝。

感謝, 傑米

回答

2

使用此在您的參數:

$args = array(
     'post_type'=> 'event', 
     'posts_per_page' => 9, 
     'orderby' => 'meta_value', 
     'meta_key' => 'date', 
     'meta_type' => 'DATE', 
     'order' => 'ASC', 
    ) 
+0

乾杯,工作完美! – user3479267