Home › Forums › Add-ons › Repeater Field › Repeated Date Range Query › Reply To: Repeated Date Range Query
Try this
function get_post_ids_within_range(){
global $wpdb;
$datenow = date(time());
$post__in = array();
$post_type = “properties”;
$acf_pref = “kidum_”;
$sql = ”
SELECT post_id,
substring_index(meta_key,’_’,2) as field_joiner,
max( case when substring_index(meta_key,’_’,-1) = ‘from’ AND UNIX_TIMESTAMP(meta_value) <= $datenow then meta_value end) as date_from,
max( case when substring_index(meta_key,’_’,-1) = ‘to’ AND UNIX_TIMESTAMP(meta_value) >= $datenow then meta_value end) as date_to
FROM $wpdb->postmeta
WHERE meta_key LIKE ‘$acf_pref%’
AND post_id IN(SELECT ID FROM $wpdb->posts WHERE post_type='{$post_type}’ AND post_status=’publish’)
GROUP BY post_id,field_joiner
having date_to <> ” AND date_from <> ”
” ;
$rows = $wpdb->get_results($sql);
foreach($rows as $row){
$post__in[] = $row->post_id;
}
return $post__in;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.