douhan8610 2015-09-06 19:31
浏览 67
已采纳

如何在自定义字段中按日期排列Wordpress帖子?

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. 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

  • 写回答

1条回答 默认 最新

  • douhui3760 2015-09-06 19:47
    关注

    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',
        )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services