Home › Forums › ACF PRO › Force default value on existing posts › Reply To: Force default value on existing posts
I can’t tell you how to do this for beaver builder specifically, I can only tell you how to make the new default value in the field apply, you would need to get someone that knows beaver builder to figure out how to do it there. Unfortunately, I don’t know of any beaver builder experts that frequent this forum.
The main issue is that since it’s a new field that has never been updated on old posts that the field and the ACF field key reference entries do not exist in the DB. The important part is the ACF field key reference. Without this reference ACF cannot get the field definition and can’t return the default.
The simplest solution in php is to use the field key to get the value rather than the field name. This allows ACF to return then default value when it is not set.
$value = get_field('field_XXXXXXXXXX');
The second option is to code it into the template
$value = get_field('your-field-name');
if (!$value) {
$value = 'some default value';
}
the only other way would be to physically insert the default value for every existing post. You’d need to create a function that runs one time.
et_field()
to get the current field valueupdate_field()
using the FIELD KEY to update the value.Depending on how many posts you need to update this action could time out and not be possible to complete. In this case you could modify the query to only return posts where the meta_key “NOT EXISTS” and cause the function to update to run several times until you get them all.
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.