Support

Account

Home Forums Backend Issues (wp-admin) update multiple fields at once through functions.php Reply To: update multiple fields at once through functions.php

  • There isn’t an easy way to do this. You will need to

    1) Get all the posts of the post type
    2) Check to see if the field already has a value
    3) update if it doesn’t

    Depending on the number of posts involved, this process could very well time out before completion.

    The better alternative is to set a default value if the field does not contain a value.

    
    $value = get_field('field_name');
    if (!$value) {
      $value = 'set some default value';
    }
    

    The checking of this may need to be more complex, but that’s the idea.

    Alternately you could add an acf/load_value filter to the field and return a default value from this and this would not require altering templates where it’s used https://www.advancedcustomfields.com/resources/acf-load_value/