Support

Account

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