Hello,
I`m have no Idea on how to make possible to query all events with repeated Dates From and Date To.
For Example:
"Event 1" has dates
[from: 2014-02-14, to: 2014-02-14],
[from: 2014-02-16, to: 2014-02-18],
[from: 2014-02-19, to: 2014-02-19]
"Event 2" has dates
[from: 2014-02-15, to: 2014-02-18],
[from: 2014-02-20, to: 2014-02-25]
Question is how can I query and get the result of from : 2014-02-15 – to: 2014-02-17
The Results should be:
Event 1 – 2014-02-16
Event 1 – 2014-02-17
Event 2 – 2014-02-15
Event 2 – 2014-02-16
Event 2 – 2014-02-17
I hope you can help me.
Best Regards,
Jhay
Hi @jhayunu
Thanks for the question. This kind of query has not yet been attempted here, so you will be the first to undertake the task!
Please first read the documentation for querying sub field values:
http://www.advancedcustomfields.com/resources/tutorials/querying-the-database-for-repeater-sub-field-values/
You will need to write some custom SQL to compare between the values, but I’m not entirely sure this can work with a ‘LIKE’ on the meta_name…
Good luck, but this is far beyond the scope of the plugin and I can’t offer too much free support for this one.
Cheers
E
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;
}