Support

Account

Home Forums ACF PRO Updating Field Settings in PHP Reply To: Updating Field Settings in PHP

  • Updating choices for a field, or any other information can be done using the acf_update_field() function. This function is not documented, but it is the function that ACF calls internally to update a field when it’s changed in the admin.

    
    // get the field... use the field key
    $field = get_field_object('field_1234567');
    
    // modify the settings of the field
    $field['choices']['new-choice-value'] = 'new choice label';
    
    // tell ACF to update the field settings
    acf_update_field($field);
    

    There are other ways to accomplish some other things that might be a better field. Filters on acf/load_field https://www.advancedcustomfields.com/resources/acf-load_field/ and acf/prepare_field https://www.advancedcustomfields.com/resources/acf-prepare_field/ can be use to temporarily alter values for display.