How to activate the default value of a custom field, created via Advanced Custom Fields?

I’m using ACF plugin, to incorporate a custom field for every page, that will determine whether to show the header image or not.

The field type is “true/false”, and the default value is set to true. The problem is, that this default value seems to come into effect, only after i re-update an existing. In other words, it doesn’t apply to an existing page, until the admin/user has updated that page.

This is the logic i use in my template:

$show_header = get_post_meta($post->ID, ‘show_header’, true);
if ($show_header && $show_header == 1) {
if (has_post_thumbnail()) {
$url =get_the_post_thumbnail_url();
echo
“<div style=’background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url({$url});’ class=’page_header’ id=’resources_header’>
<div class=’container’>
<h1 class=’page_title’>Resources</h1>
</div>
</div>”;

} else {
echo
“<div style=’background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url({$default_image_url});’ class=’page_header’>
<div class=’container’>
<h1 class=’page_title’>Resources</h1>
</div>
</div>”;
}
}

How can i force the default value to come into affect, in every page, without manually re-publishing them?

Read more here:: How to activate the default value of a custom field, created via Advanced Custom Fields?

Leave a Reply

Your email address will not be published. Required fields are marked *