Home › Forums › General Issues › Default Value not set until Update Post › Reply To: Default Value not set until Update Post
That is correct. If the field is added after the post is created the field will not have the default value until the post is updated. ACF does not retroactively set default values.
True/False fields are a little tricky because ACF will return false for it if it is not set or if it is not checked.
The best way, in my experience, to deal with this is to use get_post_meta()
<?php
$show_sidebar = get_post_meta($post->ID, 'show_sidebar', true);
if($show_sidebar === '' || $show_sidebar === '1'): ?>
<div id="sidebar">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar') ) : ?><?php endif; ?>
</div>
<?php endif; ?>
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.