Home Forums General Issues Search and Replace Image field in bulk Reply To: Search and Replace Image field in bulk

  • There isn’t an easy way to do this, which is why you’re not finding anything.

    In order to do this you would need to

    1. Do a query to get all the ACF fields that exist on the site
    2. Find all the image field keys. You’ll probably want to look at file fields and gallery fields as well.
    3. Query the post meta table for the field key reference for get the actual meta keys where the image ID is stored. The reason for this is that the actual meta key may not be the field name if the field is a sub field
    4. Use update_field() or update_post_meta() with the post ID values and meta keys gotten in step 3 and the altered value based on the field type. Image and file fields store a single ID but gallery fields store an array of image IDs. You might also use a direct DB query to do the updates.
    5. Repeat Steps 3 & 4 for both term meta and user meta

    If you are looking to change an image site wide then I would go with this which allows you to replace the media file directly so that it retains the original ID.