Support

Account

Home Forums General Issues Updating metadata (in bulk) the right way Reply To: Updating metadata (in bulk) the right way

  • If you have a URL stored then how you are attempting to get the ID is the only way that I know of to do this.

    As far as bulk updating this would be very difficult for someone that has experience, I would not attempt this.

    I would create code similar to what you have for when the post is updated, except that I would move the check to see if there is a value before I did any work

    
    // put at top of function
    if (!empty( get_field('volunteer_attachment', $post_id))) {
      // ACF field. Don't update if already it's been filled in.
      return;
    }
    

    Then try to get the ID value. When you update you need to use update_field() with the field key (not the field name) because it is an image field that does not already have a value.

    
    update_field('field_XXXXXXX', $file_id , $post_id)'
    

    Once this is in place I would alter my theme file to use the new value and use the old value if the new field does not have a value

    
    if (get_field('new_field_name')) {
      // new field has a value, use it here
    } else {
      // new field has no value, get value of old field and use it instead
    }