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条)