Support

Account

Home Forums General Issues New Field – Auto Update posts in custom post type Reply To: New Field – Auto Update posts in custom post type

  • You need to loop through the posts and update the field, yes you could do that.

    
    get posts
    while have posts
    the post
    update value
    

    But I wouldn’t.

    The best way to do this is to check the value where it is used and substitute a default value if it’s not set, it only takes a couple lines of code to deal with it.

    
    $value = get_field('your-new-field');
    if (!$value) {
      $value = 'the default value';
    }
    // do something with value
    

    you could also add an acf/load_value filter for the field in question that sets the default value if it is empty https://www.advancedcustomfields.com/resources/acf-load_value/