Sort by date, then by time

时间:2015-12-10 作者:Jill C

我们有特定日期的“事件”,因此页面设置为首先根据事件发生的日期放置事件,然后根据事件发生的时间对事件进行排序。

日期很好——所有适当的事件都在适当的日期之下。

但时间并不一致。大约80%的答案是正确的,但偶尔会有一个错误。。。。因此,我可能会看到这样的情况:(第2天显示问题)

DAY 1
 8:00am - 10:00am event 1
10:15am - 12:00pm event 2
 1:15pm -  2:00pm event 3
 3:15pm -  5:00pm event 4

DAY 2
 8:00am - 10:00am event 1
 3:15pm -  5:00pm event 4
10:15am - 12:00pm event 2
 1:15pm -  2:00pm event 3
这是处理这一领域的代码——有人能提供关于如何按升序计算时间的建议吗?

echo \'<div class="page hentry entry"><div class="entry"><ul class="conference_list">\';
$year_to_show = \'2016\';

$args = array(
    \'posts_per_page\' => -1, 
    \'meta_key\'       => \'date\', 
    \'order\'          => \'ASC\', 
    \'orderby\'        => \'meta_value\',
    \'post_type\'      => \'proposal\'
);
$myQuery = new WP_Query( $args );

$date = CFS()->get( \'date\' ); 

if ( $myQuery->have_posts() ) : while ( $myQuery->have_posts() ) : $myQuery->the_post();
    if ( date( \'Y\', strtotime( CFS()->get( \'date\' ) ) ) == $year_to_show ) {
        if ( $date != CFS()->get( \'date\' ) ) {
            $date = CFS()->get( \'date\' );
            echo \'<div class="date_title">\';
            echo date( \'F j, Y\', strtotime( CFS()->get( \'date\' ) ) );
            echo \'</div>\';
        } ?>
        <li><span><?php echo genesis_get_custom_field( \'start_time\' ); ?>  - <?php 
            echo genesis_get_custom_field( \'end_time\' );?>   </span>

1 个回复
SO网友:Felix

您可以按多种方式订购,请参见https://make.wordpress.org/core/2014/08/29/a-more-powerful-order-by-in-wordpress-4-0/:

$args = array(
    \'meta_key\' => \'start_time\',
    \'orderby\' => array(\'date\' => \'ASC\', \'meta_value\' => \'ASC)
);

相关推荐