Home › Forums › Backend Issues (wp-admin) › Setting Default Value in Blank fields › Reply To: Setting Default Value in Blank fields
If you want ACF to return the default value in the case where the field has never been updated then you need to use the field key to get the field.
$value = get_field('field_XXXXXXXX');
The reason for this is that when you use the field name ACF tries to get the field key reference that it stores in that DB for the field. Since the field has not been saved ACF cannot find the field definition so it does not know what to return as a default value.
You can do it the way you’re trying but your code is a little off
if ($value !== '')
will only change the value if there is a value, you want something like
if (empty($value)) {
$value = 'CASH';
}
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.