Support

Account

Home Forums Bug Reports get_field() can return either false or null when unset Reply To: get_field() can return either false or null when unset

  • There are times when you want to know if a value has never been set before. For example, if you want to use a default value if it has never been set, but if someone has edited the post and removed the default value then show nothing at all.

    
    $value = get_field('some_field');
    if ($value === NULL) {
      // show default value
    } elseif ($value) {
      // show value from field
    } else {
      // show nothing
    }
    

    There are probably many conditions where it is important to know if a value has never been set or the field simply does not have a value.