SELECT DISTINCT p. *
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id
JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
JOIN wp_posts AS p ON p.ID = tr.object_id
JOIN wp_postmeta AS pm1 ON ( p.ID = pm1.post_id
AND pm1.meta_key = 'date_heure_debut' ) #Join second instance of meta table (since we are checking against TWO meta keys)
JOIN wp_postmeta AS pm2 ON ( p.ID = pm2.post_id
AND pm2.meta_key = 'date_heure_fin' ) #Limit terms to a specific post type (in this case, our custom 'event' post type)
WHERE p.post_type = 'evenement'
AND (
(
(pm1.meta_key = 'date_heure_debut' AND pm1.meta_value <= '2018-10-12 23:59')
AND (pm2.meta_key = 'date_heure_fin' AND pm2.meta_value >= '2018-10-12 00:00')
)
OR (
(pm1.meta_key = 'date_heure_debut' AND pm1.meta_value like '%2018-10-12%')
)
)Aucun événement pour la période sélectionnée!