WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What am I doing wrong in this query? I want to select events from a custom post type called events and order by the event date and only show ones after the current date. It doesn't seem to work...

$querystr = "

SELECT $wpdb->posts.* 
FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id 
AND $wpdb->postmeta.meta_key = 'wpcf-start-date'
AND $wpdb->postmeta.meta_value >= CURDATE() 
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'events'
ORDER BY $wpdb->postmeta.meta_value ASC

share|improve this question
In what format are date values stored? – Rarst Oct 12 '12 at 12:53
The input format is Month dd, yyyy – Dan Lee Oct 12 '12 at 13:18
Why aren't you using WP_QUERY? – Miha Rekar Oct 12 '12 at 13:39

Your date format is wrong, MySQL date format is yyyy-mm-dd. Once you get that fixed, see WP_Query's meta_query, no need for raw SQL in this case.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.