Support

Account

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.

    1. Query all posts where the value needs to be set and loop over them
    2. use get_field() to get the current field value
    3. 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.