Home › Forums › Front-end Issues › Multiple date-conditions via array › Reply To: Multiple date-conditions via array
I really cannot tell what you’re trying to accomplish. I have reread your previous topic as well, but I cannot get a clear enough picture of it with the information you’ve provided.
With that in mind, here is a guess. If this does not work then you’ll need to give a clearer picture of what you are working with.
// Apply conditions to fields
add_filter('acf/prepare_field/name=booking_time_session_1', 'yl_check_booking_setting_exceptions');
function yl_check_booking_setting_exceptions($field){
$conditions = array();
if (have_rows('booking_setting_exceptions', 'booking_settings')) {
while (have_rows('booking_setting_exceptions', 'booking_settings')) {
the_row();
if (get_sub_field('booking_setting_exceptions_session') == '1') {
$date = date_i18n('Ymd', strtotime(get_sub_field('booking_setting_exceptions_date', 'booking_settings')));
if (empty($date)) {
// no date, skip this row
continue;
}
// Add the condition to the field
$conditions[] = array(
array(
'field' => 'field_5ed4181bd63dc', // Time field session 1 in the form
'operator' => '==', // If Value is different, then show the field
'value' => '1', // Compare against session option page value
),
array(
'field' => 'field_5ed4178dd63d7', // Time field session 1 in the form
'operator' => '!=', // If Value is different, then show the field
'value' => $date, // Compare against date option page value
)
);
} // end if (get_sub_field('booking_setting_exceptions_session') == '1')
} // end while have_rows
} // end if have_rows
$field['conditional_logic'] = $conditions;
// Return
return $field;
}
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.