Support

Account

Home Forums Add-ons Repeater Field Create New Repeater Subfield row through code Reply To: Create New Repeater Subfield row through code

  • The problem with your workaround is that you’re not updating adding the needed field_key in addition to your value. For more information on field keys see this page http://www.advancedcustomfields.com/resources/update_field/

    http://www.advancedcustomfields.com/resources/update_sub_field/
    Your first example I think that you’re using update_sub_fields wrong, but I’m not sure. When I’m inserting new data into a repeater I generally go with your second example and insert the keys.

    Also, if you use update field on the repeater field itself and provide the correct array it will add the sub fields for you, for example:

    
    $repeater_value = array(
      // a nested array for each row
      array(
        // an element for each field
        'subfield_1' => 'value 1',
        'subfield_2' => 'value 2'
      ),
      // a nested array for each row
      array(
        // an element for each field
        'subfield_1' => 'value 1',
        'subfield_2' => 'value 2'
      ),
    )
    update_field('repeater_field', $repeater_value);