我正在尝试创建一个查询,以仅提取未来事件。在客户端请求添加日期范围之前,它一直工作得很好,因此事件要么只有开始日期,要么有开始日期和结束日期。我需要构建一个查询,以提取将来有开始日期或结束日期的事件。这无法按预期工作,并会拉取所有事件;尽管将orderby设置为meta\\u值,但提取的顺序似乎是随机的。任何帮助都将不胜感激!
function get_upcoming_events($num) {
$today = gmdate(\'Y-m-d\', time()-28800);
$args = array(
\'meta_key\' => \'event_date\',
\'order\' => \'ASC\',
\'orderby\' => \'meta_value\',
\'post_status\' => \'publish\',
\'posts_per_page\' => $num,
\'post_type\' => \'events\',
\'meta_query\' => array(
\'relation\'=>\'OR\',
array(
\'key\' => \'event_date\',
\'type\' => \'DATE\',
\'value\' => $today,
\'compare\' => \'>=\'
),
array(
\'key\' => \'end_date\',
\'type\' => \'DATE\',
\'value\' => $today,
\'compare\' => \'>=\'
)
)
);
if ( isset( $data[ \'taxonomy\' ]) ) {
$args[ \'tax_query\' ] = array();
$args[ \'tax_query\' ][0] = array(
\'field\' => \'slug\',
\'taxonomy\' => \'event-type\',
\'terms\' => \'general\'
);
}
$myquery = new WP_Query( $args );
return $myquery;
}