First, you shouldn’t use NOW()
in select queries since NOW()
returns the current date and time to the split second. In other words: This query will never land in the cache.
And you can use the WP_Query with filter of posts_where
eg:
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' );