Created
November 6, 2009 23:13
-
-
Save jaywilliams/228383 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Get Wordpress posts that are within a specific date range | |
-- Useful for an events calednar. | |
SELECT wp_posts.ID, wp_posts.post_title, wp_posts.post_name, start.meta_value AS start_date, end.meta_value AS end_date | |
FROM wp_postmeta AS `end` | |
JOIN wp_postmeta AS `start` ON ( end.post_id = start.post_id ) | |
JOIN wp_posts ON ( end.post_id = wp_posts.ID ) | |
WHERE ( | |
end.meta_key = "End Date" | |
AND end.meta_value >= DATE_FORMAT( NOW() , "%Y/%m/%d") | |
) | |
AND ( | |
start.meta_key = "Start Date" | |
) | |
AND ( | |
wp_posts.post_type = "post" | |
) | |
AND ( | |
wp_posts.post_status = "publish" | |
) | |
ORDER BY start_date; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment