I am trying to pull a list of events for a date range from wordpress. There is a custom type 'event'
Date range = '2015-12-01' to '2015-12-31'.
The first select solves the problem - however we also have events that are ongoing and are depicted by an end date of '2037-01-01' so any event fits into this category. Here is what I tried to get the correct results (it works but it's not pretty and I am sure someone can offer a better solution or point out mistakes)
select * from wp_15_posts wp
join wp_15_term_relationships tr on tr.object_id = wp.ID and (term_taxonomy_id = 1707 or term_taxonomy_id = 1700 or term_taxonomy_id = 1701 or term_taxonomy_id = 1702 or term_taxonomy_id = 1703 or term_taxonomy_id = 1713 or term_taxonomy_id = 1704 or term_taxonomy_id = 3 or term_taxonomy_id = 1696 or term_taxonomy_id = 299 or term_taxonomy_id = 1695 or term_taxonomy_id = 1697 or term_taxonomy_id = 1698 or term_taxonomy_id = 1717 or term_taxonomy_id = 1705 or term_taxonomy_id = 1699 or term_taxonomy_id = 31 or term_taxonomy_id = 4 or term_taxonomy_id = 2 )
join wp_15_stack_eventmeta em3 on em3.stack_event_id = wp.ID and em3.meta_key = '_stack_event_end_date' and em3.meta_value >= '2015-12-01'
join wp_15_stack_eventmeta em4 on em4.stack_event_id = wp.ID and em4.meta_key = '_stack_event_end_date' and em4.meta_value <= '2015-12-31'
where wp.post_status = 'publish' and wp.post_type = 'event' group by wp.ID
union
select * from wp_15_posts wp
join wp_15_term_relationships tr on tr.object_id = wp.ID and (term_taxonomy_id = 1707 or term_taxonomy_id = 1700 or term_taxonomy_id = 1701 or term_taxonomy_id = 1702 or term_taxonomy_id = 1703 or term_taxonomy_id = 1713 or term_taxonomy_id = 1704 or term_taxonomy_id = 3 or term_taxonomy_id = 1696 or term_taxonomy_id = 299 or term_taxonomy_id = 1695 or term_taxonomy_id = 1697 or term_taxonomy_id = 1698 or term_taxonomy_id = 1717 or term_taxonomy_id = 1705 or term_taxonomy_id = 1699 or term_taxonomy_id = 31 or term_taxonomy_id = 4 or term_taxonomy_id = 2 )
join wp_15_stack_eventmeta em3 on em3.stack_event_id = wp.ID and em3.meta_key = '_stack_event_end_date' and em3.meta_value = '2037-01-01'
join wp_15_stack_eventmeta em4 on em4.stack_event_id = wp.ID and em4.meta_key = '_stack_event_end_date' and em4.meta_value = '2037-01-01'
where wp.post_status = 'publish' and wp.post_type = 'event' group by wp.ID order by 30
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire