我们在wordpress上发布了一些按日期排序的活动。所有这些都很好,除非我们参加2020年的活动,它会排在列表的顶部而不是底部。日期保存在数据库中为“2020年1月24日”
2019年的所有活动都按天、然后按月进行了正确排序,下一次将在列表顶部显示。
下面是查询的代码。我不确定这是问题所在的查询、数据库还是两者兼而有之。感谢您的帮助或建议。
if( $data[\'items_per_page\'] ) {
$event_perpage = $data[\'items_per_page\'];
}
else {
$event_perpage = \'10\';
}
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'post_type\' => \'event\',
\'posts_per_page\' => $event_perpage,
\'paged\' => $paged,
\'meta_key\' => $prefix.\'event_date\',
\'orderby\' => \'meta_value\',
\'order\' => \'ASC\'
);
$wp_query = new WP_Query($args);
if($wp_query->have_posts()) :
while($wp_query->have_posts()) :
$wp_query->the_post(); ?>
<?php
// Get event date
$e_date = get_post_meta($post->ID, $prefix.\'event_date\', true);
$e_date_end = get_post_meta($post->ID, $prefix.\'event_date_end\', true);
if ( $e_date !== \'\' ) {
$event_date_string = $e_date;
$event_year = mysql2date( \'Y\', $event_date_string );
$event_monthM = mysql2date( \'M\', $event_date_string );
$event_day = mysql2date( \'d\', $event_date_string );
$event_month = apply_filters(\'get_the_date\', $event_monthM, \'M\');
}
// If no date set
else {
$event_month = "No Date";
$event_day = "00";
$event_year = \'\';
}
if ( $e_date_end !== \'\' ) {
$event_date_end_string = $e_date_end;
$event_year_end = mysql2date( \'Y\', $event_date_end_string );
$event_monthM_end = mysql2date( \'M\', $event_date_end_string );
$event_day_end = mysql2date( \'d\', $event_date_end_string );
$event_month_end = apply_filters(\'get_the_date\', $event_monthM_end, \'M\');
}
// Get event time
$e_time = get_post_meta($post->ID, $prefix.\'event_time\', true);
if ( $e_time !== \'\' ) { $event_time = $e_time; }
else { $event_time = __(\'No time set\',\'qns\'); }
// Get event location
$e_location = get_post_meta($post->ID, $prefix.\'event_location\', true);
if ( $e_location !== \'\' ) { $event_location = $e_location; }
else { $event_location = __(\'No location set\',\'qns\'); }
谢谢你。