Support

Account

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

  • Repeaters do not store values as a multidimensional array. If you must have the field that holds a multidimensional array and this field already exists then you’re going to need to have two ways of storing the data.

    The first thing that you’re going to need to do is create an acf/load_value filter http://www.advancedcustomfields.com/resources/acfload_value/ for the repeater. The array is already formatting the way it needs to be, you just need to use the value from the other field.

    
      
      add_filter('acf/load_value/name=my_repeater_field',
                        '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, 'the_original_field', true));
        return $load_value;
      }
    

    The second thing you’re going to need to do is create an acf/save_post filter http://www.advancedcustomfields.com/resources/acf_save_post/ for the repeater that puts the new value back into your original field. This filter needs to run after ACF has updated the field 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) != 'my_post_type') {
          return;
        }
        $value = get_field('my_repeater_field', $post_id);
        update_post_meta($post_id, 'the_original_field', $value);
      }