Skip to content

Instantly share code, notes, and snippets.

@jaywilliams
Created November 6, 2009 23:13
Show Gist options
  • Save jaywilliams/228383 to your computer and use it in GitHub Desktop.
Save jaywilliams/228383 to your computer and use it in GitHub Desktop.
-- 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