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
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.