Home Forums ACF PRO Unique, pre-populated repeater fields Reply To: Unique, pre-populated repeater fields

  • In order to pre-populate a repeater and have unique values for each row you need to populate the entire repeater in one go.

    here’s an example:

    add_filter('acf/load_value/key=field_123456', 'pre_pop_repeater', 20, 3);
    /* in the above the field_123456 is the field key of your repeater */
    function pre_pop_repeater($value, $post_id, $field) {
      if ($value != NULL) {
        // if the acf value is not null then
        // repeater was previously saved
        // and we should not override
        return $value;
      // return an array
      $value = array(
        // each element of the array represents a row
          // this is the first row
          // set value for every field in the row
          // the values are field_key => value pairs
          'field_678' => 'value for this field',
          'field_789' => 'value for this field'
          // etc...
          // this is the second row
          // etc....
      return $value;