首先,你不应该使用NOW()
在“选择查询自”NOW()
将当前日期和时间返回到分秒。换句话说:此查询永远不会在缓存中着陆。
您可以使用WP\\u查询和posts_where
例如:
function filter_event_where( $where = \'\' ) {
$date = date(\'Y-m-d\');
$where .= " AND posts.post_date < \'".$date."\'";
return $where;
}
add_filter( \'posts_where\', \'filter_event_where\' );
$today = date(\'Y/m/d\', strtotime("now"));
$query = new WP_Query( array(
\'meta_key\' => \'event_date\', //used for order
\'orderby\' => \'meta_value\', //used for order
\'post_type\' => \'event\',
\'meta_query\' => array(
array(
\'key\' => \'event_date\',
\'value\' => $today,
\'compare\' => \'>=\'
)
)
));
remove_filter( \'posts_where\', \'filter_event_where\' );