admin管理员组文章数量:1122846
We have "events" that are specific dates, so the page is set to put the events based on the day of the event first - then they should be sorted by the time the event takes place.
The dates are fine -- all the proper events are under the proper dates.
But the times are not consistent. About 80% of them are correct but every once in a while one falls out of place....so I may see something like this: (DAY 2 shows the issue)
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
This is the code that handles this area - can anyone offer advice on how to get the TIMES in ascending order as well?
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>
We have "events" that are specific dates, so the page is set to put the events based on the day of the event first - then they should be sorted by the time the event takes place.
The dates are fine -- all the proper events are under the proper dates.
But the times are not consistent. About 80% of them are correct but every once in a while one falls out of place....so I may see something like this: (DAY 2 shows the issue)
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
This is the code that handles this area - can anyone offer advice on how to get the TIMES in ascending order as well?
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>
Share
Improve this question
edited Dec 10, 2015 at 20:21
Gabriel
2,24810 gold badges22 silver badges24 bronze badges
asked Dec 10, 2015 at 19:14
Jill CJill C
11 silver badge2 bronze badges
5
|
1 Answer
Reset to default 0You can order by multiple things see more on 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)
);
本文标签: custom post typesSort by datethen by time
版权声明:本文标题:custom post types - Sort by date, then by time 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736284755a1927317.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
Ymd His
format or unix timestamp format. Any other format will not sort properly. This is unfortunately how custom fields work. There are a way to solve your issue, but it is really expensive and will slow things down, something that you also would not want. Best solution is to rethink how your dates are stored – Pieter Goosen Commented Dec 11, 2015 at 4:33