Images in WordPress posts, as I understand, are uploaded manually. They are uploaded by default to uploads
folder. A client of mine reported that, in one of his site, he uploaded all the images in BMP format. Now he realized the consequences of his mistake. He wants to make them JPG now. And there are 40-60 images there.
With a photo editor I can change the images in uploads folder from BMP to JPG. But the problem is the database. I’ve seen that in _postmeta
table images are stored with the meta_key _wp_attached_file
with meta_value like 2011/01/canola2.jpg
. And the same image is also in _posts
table with a detailed path as guid, post_type attachment
and post_mime_type image/jpeg
. So may be a similar things happen to the BMP images as well.
So, along with the image file format changes in uploads
folder how can I bulk edit the db to make them available only with a minor change in their format in database? Any SQL query?
Or, do I have to do the big change manually, one by one?
Assuming you add the files with the matching filenames in the appropriate
wp-content/uploads/
folders you could run a few SQL queries to update the WordPress database to use the.jpg
files.Assuming your
wpdb
prefix iswp
these queries would be:Here is a plugin that can accomplish that. https://wordpress.org/plugins/better-search-replace/
Just select
wp_posts
andwp_posts_meta
, check the GUID box, and replaceimage/bmp
withimage/jpeg
and.bmp
with.jpg
I changed 5000 images in about 20 seconds.