Thanks for the help so far, this thread has been very helpful.
I am also trying to use WP as an event listing. I have two custom fields I want to use to filter and sort the postings: startdate and enddate.
The filtering seems to work and so does the sorting, but I am getting 3 of each posting returned when I run the loop.
Can anyone point out where I am going wrong here?
Thanks!
<?php
$querystr = "
SELECT * FROM $wpdb->posts
LEFT JOIN $wpdb->postmeta AS startdate ON(
$wpdb->posts.ID = startdate.post_id
AND startdate.meta_key = 'startdate'
)
LEFT JOIN $wpdb->postmeta AS enddate ON(
$wpdb->posts.ID = enddate.post_id
AND enddate.meta_key = 'enddate'
)
LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
WHERE $wpdb->posts.post_status = 'publish'
AND enddate.meta_value > CURDATE()
AND startdate.meta_value <= DATE_ADD(CURDATE(),INTERVAL 30 DAY)
ORDER BY enddate.meta_value, startdate.meta_value ASC
";