1

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

"; 
  • 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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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