Support

Account

Home Forums ACF PRO How to update the db with a default value Reply To: How to update the db with a default value

  • In most cases it would be much easier to alter the code in your template to check for a value an if it does not exist then show the default.

    
    $value = get_field('my_field');
    if ($value === false) {
        $value = 'default_value';
    }
    

    To do it the other way, you can:

    • create a temporary function that runs on a WP hook
    • Do a query that gets all the posts in the post type you want to update
    • Loop through all the posts and check the field
    • If the field is empty, update the field with the default value

    I generally do the former and code my templates to deal with default values because I assume that any field might be empty.