I have posts. I am creating a new field with a default value. It won’t take it unless I create a new post. I need existing posts to accept the default value of the new field. I found other posts about this problem, but my problem is that I am doing this with acfpro + beaver builder.
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.
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.
Query all posts where the value needs to be set and loop over them
use get_field() to get the current field value
if no value is returned use update_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.