Support

Account

Home Forums ACF PRO Different Default Value For Repeater Field Rows

Solved

Different Default Value For Repeater Field Rows

  • Hi, I wonder if anyone can point me in the right direction here 🙂
    I have a repeater field with 6 automatic rows.

    Within the repeater is a taxonomy field.

    What I really want to be able to do is specify a default value for a different selected taxonomy on each of the generated repeater rows.

    So Row one would have ‘Category 1’ selected by default
    Row 2 would have ‘Category 2’ selected by default etc etc…

    Is this possible?
    Many thanks in advance

  • You could try using acf/prepare_field https://www.advancedcustomfields.com/resources/acfprepare_field/

    This example is using a text field, not a select field, just to give you some idea of what you could do.

    
    add_filter('acf/prepare_field/key=field_576ac7aa4eea4', 'preparefield');
    function preparefield($field) {
      // see all the field settings before changing
      echo '<pre>'; print_r($field); echo '</pre>';
      
      // get the current row
      if (preg_match('/([0-9]+)\]$/', $field['prefix'], $matches)) {
        $row = intval($matches[1]);
        // set default value based on row
        $field['default_value'] = $row;
      }
      return $field;
    }
    
  • Excellent, that did exactly what I needed, thank you 🙂

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

The topic ‘Different Default Value For Repeater Field Rows’ is closed to new replies.