Home › Forums › Add-ons › Repeater Field › Using acf_form() to store/fetch a multidimensional array meta_key › Reply To: Using acf_form() to store/fetch a multidimensional array meta_key
looking it over I missed something in the last code I posted
add_filter('acf/load_value/name=test_repeater','load_my_repeater_field_value', 10, 3);
function load_my_repeater_field_value($value, $post_id, $field) {
$load_value = maybe_unserialize(get_post_meta($post_id, 'inserted_into_repeater', true));
if (!is_array($load_value)) {
return $value;
}
if (is_array($load_value)) {
$load_value = $load_value[0];
foreach ($load_value as $index => $row) {
if (count($row)) {
$load_value[$index]['from'] = str_replace('-', '', $load_value[$index]['from']);
$load_value[$index]['to'] = str_replace('-', '', $load_value[$index]['to']);
} // end if count row
} // end foreach row
} // end if is array
return $load_value;
};
add_filter('acf/save_post', 'update_my_repeater_field_value', 20);
function update_my_repeater_field_value($post_id) {
// check the post type
// you don't want to do this on every post type
if (get_post_type($post_id) != 'product') {
return;
}
$value = get_field('my_repeater_field', $post_id);
if (is_array($value)) {
foreach ($value as $index => $row) {
if (count($row)) {
$value[$index]['from'] = date('Y-m-d', strtotime($value[$index]['from']));
$value[$index]['to'] = date('Y-m-d', strtotime($value[$index]['to']));
} // end if count row
} // end foreach row
}
$value = array($value);
update_post_meta($post_id, '_wc_booking_availability', $value);
}
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.