Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
1  
10 Questions -> 0% accept rate. –  Brian Fegter Oct 12 '12 at 12:51
    
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
1  
Why aren't you using WP_QUERY? –  Miha Rekar Oct 12 '12 at 13:39

1 Answer 1

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

 
discard

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.