Fix broken images in WordPress with SQL queries

I used the Export and Import tools in WordPress to move this site to new web hosts, twice. In the process, many of the images were broken. They didn't appear in the page, and I could see that the links all pointed to file names ending in 1, such as picture1.jpg, picture1.png, and picture1.gif. My guess is that WordPress tried to avoid duplicate filenames by appending 1 to the ends of the filenames.

Fortunately, this was easy to fix. I opened my database in phpMyAdmin and searched for %1.jpg. It looked like the offending filenames were in the wp_posts table, in the post_content field. I referenced this Onextrapixel post: 13 Useful WordPress SQL Queries You Wish You Knew Earlier.

I ran the following 3 SQL queries to fix the images:

UPDATE wp_posts SET post_content = REPLACE (post_content, '1.jpg', '.jpg');
UPDATE wp_posts SET post_content = REPLACE (post_content, '1.png', '.png');
UPDATE wp_posts SET post_content = REPLACE (post_content, '1.gif', '.gif');
update wp_posts set post_content sql
Filed Under: 
Tagged With: ,

Want tips to rocket-boost your website?

Simply sign up.

Leave a Reply

Your email address will not be published. Required fields are marked *

Ready to Blast Off?

Let's talk.

Contact OptimWise
crossmenuarrow-right