Support

Account

Home Forums General Issues Programmatically Creating Records Containing a Repeater Reply To: Programmatically Creating Records Containing a Repeater

  • Using add_post_meta() will only work with an ACF field if it is a simple type of field. This means anything listed under “Basic” field types. You should be using update_field() and using the field key to update all ACF fields, as explained here https://www.advancedcustomfields.com/resources/update_field/ to ensure that the fields are created correctly.

    Adding content to a repeater can be done the same way. Let say for example that the field key of the repeater is “field_1”, and the sub fields are “field_2” for network and “field_3” for url.

    
    // construct an array for the repeater value
    $value = array(
      // each row is a nested array
      array(
        // row 1
        // each row contains field key => value pairs for the fields
        'field_2' => 'name of network',
        'field_3' => 'url value'
      ),
      array(
        // row 2
        'field_2' => 'name of network',
        'field_3' => 'url value'
      ),
      // etc for each row
    );
    // update the repeater
    update_field('field_1', $value, $post_id);