Skip Navigation

[Resolved] Bulk Rename of the content of custom Image field

This support ticket is created 4 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by mikeS-32 4 years, 1 month ago.

Assisted by: Christian Cox.

Author
Posts
#1764409

I have a custom Image field in which I enter a URL to a photo that is hosted on another server. I don't use the Media Library to store my photos - Too many photos, file structure to complex to replicate in media library, and when photos get edited I don't want to have to replace them into the media library every time. It seems to work fine to just put the URL in the Image Field and serve them up from another host. (FWIW at the moment the host is a localhost:8888, but it might change in the future, hence the bulk rename question)

Problem is what if I want to change the name of the host or the directory string in the URL? I need to do a bulk find and replace in that field for all posts.

Seems like some SQL ought to do the trick. I'm no expert at SQL but have played with it in the past. Where do I start? Other options? PS, is there a better way to handle my photo situation?

Thanks,

Mike

#1764539

Problem is what if I want to change the name of the host or the directory string in the URL? I need to do a bulk find and replace in that field for all posts.
I think a SQL Query of some kind is necessary here, whether that is hand-crafted or automated by a database find-and-replace plugin or script. Toolset does not offer such a wildcard replacement feature for image URLs, and in general we do not provide custom SQL scripts here in the forum. Even the 3rd-party plugins I know of that support bulk editing of custom fields do not include wildcard text string replacement, which is what you would really need here. If I needed to do something like you have described, I would start by searching for a WordPress plugin that offers "database find and replace", or something like "database migration tool" that allows you to specify arbitrary text strings you want to replace. Please note that replacing text in serialized data structures without the proper adjustments will crash your site, so it's very important you look for a plugin that supports find-and-replace in something called serialized data structures. This database data format is like a shorthand for storing multiple values in the same field. Some custom field types store data in serialized data format, as well as Views and Layouts, so just to be on the safe side I recommend you find a system that explicitly supports data serialization.

I don't really have a preferred recommendation for you, unfortunately. Usually when I migrate a site to a different server I use a tool like Duplicator Pro, but that plugin does not allow you to specify arbitrary URLs for replacement. As far as I know it is designed to scan specifically for the old site URL and replace it with the new site URL, which isn't helpful in your case. A quick search led me to these two you might use as a starting point for your own research:
https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
https://wordpress.org/plugins/wp-migrate-db/

Always back up your database before you try any direct manipulation, regardless of the tool you choose. Hope this helps you.

#1764585

Thanks for the insight. It's a bit much for me to bite off right now. I can get around the issues for the time being, but I'll eventually have to deal with it. To wrap up this ticket, two questions:

1) The interconnectit video described a process by which it appears the entire database is exported to a text file, the find and replace is executed on the text file, and then the text file is imported back into MYSQL. Does make sense? I'd think I'd just be executing a find and replace within MYSQL itself.

2) It looks like Toolset does not create any new tables and just uses the existing WordPress tables. Is that right? So, when I do get to changing the data in the Image custom field, is the WP-Post table the only one that I have to deal with?

Thanks,

Mike

#1765399

1. It might make sense especially if you want to upload the modified database to a test environment before applying the update to your original database.

2. Sometimes Toolset uses a table called "wp_toolset_post_guid_id" to store image guids. These often contain the URL of the image, so you should consider this table as well if you plan to update the guids.

#1765557

This was/is a difficult problem that I created for myself. There is no clean solution within Toolset's perview. I appreciate Christian's insight and tips.

Thanks,

Mike

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.