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';