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.
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.