Support

Account

Home Forums General Issues Search and Replace Image field in bulk

Helping

Search and Replace Image field in bulk

  • Hi,

    Is there a safe way to search and replace the image field in bulk?

    I understand that ACF saves the image ID and I’ve been looking for a plugin to safely do it but haven’t found any.

    Thanks

  • 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 https://wordpress.org/plugins/enable-media-replace/ which allows you to replace the media file directly so that it retains the original ID.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Search and Replace Image field in bulk’ is closed to new replies.