How to dynamically insert new selections into ACF select field via code?

I’m working on a data migration project where I need to create WordPress posts with custom field values. Everything works fine for basic text inputs and dropdown menus where the options already exist. However, I’m stuck on how to programmatically create new dropdown options when they don’t exist yet.

Basically, I want to achieve the same result as manually adding choices in the WordPress admin area, but through PHP code instead. In the backend, you can add options by typing them into the choices textbox, one per line. You can also set custom values like blue : Blue Color.

Is there a way to modify the available choices for a select field using ACF functions or WordPress hooks? I’ve been searching but can’t find a clear solution for this.

Use the acf/load_field filter hook. I’ve done this on several migration projects and it works great. Hook into the field loading process and modify the choices array dynamically from your data source.

function modify_select_choices($field) {
    if ($field['name'] == 'your_field_name') {
        $new_choices = array(
            'blue' => 'Blue Color',
            'red' => 'Red Color'
        );
        $field['choices'] = array_merge($field['choices'], $new_choices);
    }
    return $field;
}
add_filter('acf/load_field/name=your_field_name', 'modify_select_choices');

For migrations, build the choices array from your data source first, then apply the filter. This ensures all options exist before creating posts. Just run this code before your migration script processes the posts.

try using update_field() with the field key instead of name. i’ve found this way more reliable during migrations - field names change but keys don’t. just grab the field object with get_field_object(), modify the choices array, then save it with acf_update_field(). way better for large datasets.

Had this exact problem when migrating from an old CMS. I modified the field definition straight in the database before running the migration. Just query the wp_posts table for your field group, then update the field’s serialized data to add your new choices. Works great when you’ve got a set list of options from your source data. Once you update the field definition, you can use update_field() like normal and everything validates against your expanded choices. Back up your database first though - you’re messing with ACF’s core field config. Saved me hours vs loading choices dynamically on every page.