终于找到了。此代码位于函数中。php:
function set_order_by_last_date($query){
$query->set( \'orderby\', \'eventstart\');
$query->set( \'order\', \'DESC\' );
$query->get_posts();
if ($query->have_posts()){
if ( eo_get_the_end(\'Ymd\',$query->posts[0]->ID,$query->posts[0]->occurrence_id) > date(\'Ymd\') ){
$query->set( \'event_end_after\', \'today\' );
$query->set( \'orderby\', \'eventstart\');
$query->set( \'order\', \'ASC\' );
} else {
$query->set( \'event_end_before\', \'today\' );
$query->set( \'orderby\', \'eventstart\');
$query->set( \'order\', \'DESC\' );
}
}
return $query->query_vars;
}
从模板文件调用,使用:
<?php query_posts(set_order_by_last_date(clone $wp_query));?>
vars和eo\\uu功能来自优秀的活动组织者插件。谢谢杰克·约翰逊的指点。