Support

Account

Home Forums ACF PRO Populate Dynamic Select Field Reply To: Populate Dynamic Select Field

  • can you clarify a bit on what do you mean by “clear the old values”?
    do you mean, don’t populate the previously saved values?

    if that’s the case, you can overwrite the “value” key.

    
    add_filter('acf/prepare_field/name=unique_field_name', 'acf_clear_saved_value');
    function acf_clear_saved_value($field) {
        $field['choices'] = YOUR_DYNAMIC_CHOICES;
    
        // flush/clear the saved value
        $field['value'] = null;
    
        // or, set it to whatever the default
        $field['value'] = $field['default_value'];
    
        return $field;
    }
    

    p.s. In order to “flush/clear” the value, your select field setting needs to have “allow null” enabled.

    Cheers