Need help with query using custom fields
-
I have a category of posts for “events” and am using a custom field for the event date (that is different from the posting date). I need to have a section in my sidebar for “upcoming events” that will list the permalink to those events which have future dates, not events that have already passed.
In searching the Codex I found examples on how to structure a query on the post’s custom fields, but since I am not a php programmer I don’t know how to structure the query to check the custom field (‘event_date’) against the current date of any given date that someone could be looking at the blog, in order to display future (upcoming) events only.
I found this in the Codex:
<?php $querystr = " SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'tag' AND wpostmeta.meta_value = 'email' AND wposts.post_status = 'publish' AND wposts.post_type = 'post' ORDER BY wposts.post_date DESC "; $pageposts = $wpdb->get_results($querystr, OBJECT); ?>Where it shows wpostmeta.meta_key as ‘tag’, mine is ‘event_date’, and where it shows wpostmeta.meta_value as ’email’, mine is a date in this format: mm/dd/yy
Can anyone tell me how to modify the code above to check the event_date against the current date in order to display links to only those posts whose event_date is equal or greater than the current date?
Many thanks for any help anyone can offer!
The topic ‘Need help with query using custom fields’ is closed to new replies.