Home Forums Feature Requests Starting Rows – Repeater Field


Starting Rows – Repeater Field

  • So this is a minor aesthetic change, but would be neat if not difficult to implement. I often want to set a starting number of rows for a repeater field (e.g. when going to edit, show 4 rows by default). The only way to do this at the moment is to set a minimum number of rows, which isn’t ideal as occasionally there might need to be fewer rows than the default.

  • This can be done with the acf/load_value filter

    add_filter('acf/load_value/name='your-repeater-field-name', 'your_set_repeater_default_values_function_name', 10, 3);
    function your_set_repeater_default_values_function_name($value, $post_id, $field) {
      if ($value !== NULL) {
        // value will be exactly NULL if the field has never been updated
        // ie on a new post. If it is not null then you don't want to
        // overwrite what's there
        return $value;
      // set new value
      $value = array(
        // a nested array for each row
          // and array item for each field
          // use field keys
          'field_1234567890abc' => 'default value',
          'field_01234567890ab' => 'default value',
          // etc...
        // another row
          // etc...
  • Fantastic – did not know about that – thank you

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Starting Rows – Repeater Field’ is closed to new replies.