Combine two ACF date and time fields into a single date/time field
-
Hi, I’ve following this tutorial successfully, and I’ve been able to put in a calendar my events based in ACF custom fields. The problem is that I have a date picker field and a time picker field for both the start date and time and end date and time fields. I could change the fields for date/time pickers, but unfortunately, I can’t do that, since events are submitted in the frontend by the owner of the website, and the form plugin I’m using does not have a date/time field (thus, I can’t map that with a ACF date/time field).
So, I’ve tried to tweak your code to combine my ACF
start_date_acf
,start_time_acf
,end_date_acf
andend_time_acf
fields into a date/time field and this is what I’ve got so far:add_filter(
"piecal_event_query_args",
function ($args, $atts) {
$args["meta_query"] = [
"relation" => "AND",
[
"key" => "$key",
"value" => "",
"compare" => "!=",
],
];
return $args;
}, 10, 2);
add_filter("piecal_start_date_meta_key", function ($key) {
$key = date("Y-m-d\TH:i:s", strtotime(get_field('start_date_acf', $post->ID) . ' ' . get_field('start_time_acf', $post->ID)));
return $key;
});
add_filter("piecal_end_date_meta_key", function ($key) {
$key = date("Y-m-d\TH:i:s", strtotime(get_field('end_date_acf', $post->ID) . ' ' . get_field('end_time_acf', $post->ID)));
return $key;
});This doesn’t have the desired effect. I can feel I’m close to the solution, but I need the final touch (needless to say, I’m not an expert developer). Can you help me with that? Thank you for taking the time to read my question.
- You must be logged in to reply to this topic.