I would suggest storing the date-times as either:
- Timestamp (to sort/compare by
meta_value_num
) - ‘yyyy-mm-dd hh:mm (e.g. 2012-04-11 19:37) to sort/compare by
meta_value
Then the following will work (assuming you’re using timestamp):
$now = current_time('timestamp');
$args = array(
'post_type' => 'rides',
'posts_per_page' => 3,
'meta_query' => array(
array(
'key' => 'date',
'value' => $now,
'compare' => '>'
)
)
);
//This breaks pagination!
query_posts($args)
See Codex on WP_Query
.
For bonus points: don’t use query_posts
! (See this). It’s inefficient and requires some extra work to get pagination etc to work.
I suggest you see this (very) related post which shows you how to use the pre_get_posts
hook instead. That post also includes how to sort by your custom ‘date’ field.