Support

Account

Home Forums Add-ons Repeater Field Dynamically Populate Repeater Field with Users Reply To: Dynamically Populate Repeater Field with Users

  • There isn’t enough information to give an exact answer, but in general you can pre-populate a repeater this way.

    
    // this filter has the field key of the repeater field
    add_filter('acf/load_value/key=field_123456', 'my_repeater_values', 20, 3);
    function my_repeater_values($value, $post_id, $field) {
      
      // generate rows of the repeater
      // see next code snippet
    
      return $value;
    }
    

    The value you generate needs to be a nested array

    
    // $value format
    $value = array(
      // you add a nested array for each row
      array(
        // this nested array holds the field key => value pairs for each sub field
        'field_234567' => 'value of sub field 1',
        'field_345678' => 'value of sub field 2'
      ),
      // second row of repeater
      array(
        // this nested array holds the field key => value pairs for each sub field
        'field_234567' => 'value of sub field 1',
        'field_345678' => 'value of sub field 2'
      ),
      // etc....
    )
    

    this does not include any checking. For example, you probably do not want to overwrite existing values/rows and want to add new rows when new users are added. I also don’t know exactly what information you want to store.

    However, I would probably store the commission information you want to store as a custom field on the user profile page in a field group that is only available to site admins and then get the information from there when I need it.