这是我的问题查询,它选择所有未来或挂起的事件
请注意,有些帖子只有\\u开始日期,没有\\u结束日期(1天事件)。
$args = array(
\'post_type\'=> \'events\',
\'meta_query\' => array(
array(
\'key\' => \'_startdate\',
\'value\' => $today,
\'type\' => \'DATE\',
\'compare\' => \'>=\'
),
array(
\'key\' => \'_enddate\',
\'type\' => \'DATE\',
\'value\' => $today,
\'compare\' => \'>=\'
),
\'relation\' => \'OR\',
),
\'meta_key\'=> \'_city\',
\'orderby\' => \'meta_value\',
\'order\' => \'ASC\',
) ;
在我改变之前一切都很好
_city 到
_startdate 或
_enddate.
您能帮我查询一下(按开始日期排序)吗?谢谢
SO网友:WraithKenny
You could try
$args = array(
\'post_type\'=> \'events\',
\'meta_query\' => array(
array(
\'key\' => \'_startdate\',
\'value\' => $today,
\'compare\' => \'>=\',
\'type\' => \'DATE\',
),
array(
\'key\' => \'_enddate\',
\'value\' => $today,
\'compare\' => \'>=\',
\'type\' => \'DATE\',
),
\'relation\' => \'OR\',
),
);
function jumpin_thru_hoops( $a ) {
global $wpdb;
$a = $wpdb->postmeta.\'.meta_value+0 ASC\';
return $a;
}
add_filter( \'posts_orderby\', \'jumpin_thru_hoops\' );
$upcoming = new WP_Query( $args );
// or
$upcoming = get_posts( $args );
remove_filter( \'posts_orderby\', \'jumpin_thru_hoops\' );