Support

Account

Home Forums Bug Reports Setting $field['default_value'] not working in acf/prepare_field Reply To: Setting $field['default_value'] not working in acf/prepare_field

  • I also had some difficulty getting the $field['default_value'] to work in the acf/prepare_field. @dreiqbik got me on track (thanks!). You can obviously use another filter, but if you need to define the default value when preparing the field, using $field['value'] can imitate the $field['default_value'].

    This will override any selected value though, so you’ll have to filter it yourself. Check if it already has a value set, and if you don’t know if the field allows for null, you should check for that too:

    if(!$field['value'] && !$field['allow_null']) {
        $field['value'] = 'YOUR DEFAULT VALUE';
    }