您当前的元查询体现了逻辑
IF event_end IN range
OR event_start IN range
您需要考虑
event_end
\'s单独存在:
IF event_end IN range
OR ( event_end NOT EXISTS AND event_start IN range )
具有相同和/或的紧邻嵌套子句
relation
可以组合使用,这可能会使内容更具可读性。
a AND ( b AND ( c OR d ) ) === a AND b AND ( c OR d )
a OR ( b OR ( c AND d ) ) === a OR b OR ( c AND d )
您还可以
name your clauses 为了对使用的结果进行排序,但我还没有对此进行测试。
在实践中,上述所有内容:
$past_args = array(
\'post_type\' => \'event\',
\'meta_query\' => array(
\'relation\' => \'AND\',
array(
\'relation\' => \'OR\',
// check to see if end date has been set and is in range
\'end_clause\' => array(
\'key\' => \'end_date\',
\'compare\' => \'BETWEEN\',
\'type\' => \'NUMERIC\',
\'value\' => array($past, $now),
),
// if no end date has been set use event/start date
array(
\'relation\' => \'AND\',
array(
\'key\' => \'end_date\',
\'compare\' => \'NOT EXISTS\',
),
\'start_clause\' => array(
\'key\' => \'event_date\',
\'compare\' => \'BETWEEN\',
\'type\' => \'NUMERIC\',
\'value\' => array($past, $now),
),
),
),
array(
\'key\' => \'event_type\',
\'value\' => array(\'Singlar\', \'Multi-Day\', \'Series\'),
),
array(
\'key\' => \'include_in_past_events\',
\'value\' => \'1\',
)
),
// \'meta_key\' => \'event_date\',// not needed when ordering by clause name.
\'orderby\' => \'end_clause start_clause\',
\'order\' => \'DESC\',
\'nopaging\' => false,
\'posts_per_page\'=> \'8\',
);