Support

Account

Home Forums Add-ons Repeater Field Update field with repeater + relationship Reply To: Update field with repeater + relationship

  • When you update the repeater field the values need to be in a nested array, you will also need to use field keys instead of field names.

    
    // replace field keys with your real field keys
    // Sponsor -> field name(repeater field) - field key (field_XXXXXXX')
    // Select sponsors -> Sub field.(relationship) - field key (field_YYYYYYY')
    $repeater_value = array(
      // each nested array is a row in the repeater
      array(
        // each row contains field key => value pairs for each sub field
        // select field
        'field_YYYYYYY' => array(1142,1141)
      )
    )
    // update field using repeater field key
    update_field('field_XXXXXXX', $repeater_value, $post_id);
    

    alternately you can use update sub field explained here https://www.advancedcustomfields.com/resources/update_sub_field/