wp query - How to rearrange posts based on input field values added by WordPress "Advanced Custom Fields"

I want to sort the posts in ascending order based on the value of the input field added in Advanced Custom Fields.<?p

I want to sort the posts in ascending order based on the value of the input field added in Advanced Custom Fields.

<?php
$args = array (
    'post_type'         => 'post',
    'post_status'       => 'publish',
    'category_name'     => 'events',
    'orderby'             => 'meta_value',
    'meta_key'             => 'event_date',
    'order'             => 'ASC',
    'posts_per_page'    => 10,
);
?>

<?php
$query = new WP_Query( $args );

if ( $query->have_posts() ) {
    while( $query->have_posts() ) {
        $query->the_post();
        echo '<p>' . get_field('event_date') . ' ' . get_field('event_start_time') . ' ~ ' . get_field('event_end_time') . '</p>';
    }
    wp_reset_postdata();
}
?>

Output Result The start time and end time are not changed even though they are sorted by the date of the event.

20190718 1800 ~ 1900
20190718 1900 ~ 2100
20190718 1000 ~ 1500
20190718 1715 ~ 1815
20190718 0900 ~ 1030
20190718 1400 ~ 1600
20190718 0900 ~ 1000
20190719 1900 ~ 2300
20190719 2000 ~ 2200
20190719 0900 ~ 1600

ideal result

 20190718 0900 ~ 1000
 20190718 0900 ~ 1030
 20190718 1000 ~ 1300
 20190718 1000 ~ 1500
 20190718 1400 ~ 1600
 20190718 1700 ~ 1800
 20190718 1715 ~ 1815
 20190718 1800 ~ 1900
 20190718 1900 ~ 2100
 20190719 0900 ~ 1600
 20190719 1900 ~ 2300
 20190719 2000 ~ 2200

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745313261a4622097.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信