SELECT post_id FROM wp_posts p LEFT JOIN wp_postmeta pm ON p.ID = pm.post_id WHERE p.post_status='publish' AND pm.meta_key='_EventEndDate' AND DATE_FORMAT(pm.meta_value,'%Y-%m-%d %H:%i:%s') < NOW() AND pm.post_id NOT IN(SELECT post_id FROM wp_postmeta WHERE meta_key='ves_event_survey_sent' AND meta_value='1')Array ( ) MI Academy