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';
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.