Moving WordPress: Fixing Broken Images in Posts and Pages
Moving WordPress – Updating Image URLs in WordPress Posts Like a Ninja Might
The move was quite smooth – almost eerily so in fact. I always calculate my time for a WordPress migration with five hours of padding. Not that I’ll need it or want to bill for it if I don’t have to, but because there’s simply no accounting for the way a pseudo-random collection of WordPress plugins have handled their metadata, and it’s often necessary to go hunting for things that are broken in non-obvious ways.
So, for PeaceEngine, the original install was pretty well behaved. I was able to port all of the posts, pages, and comments without a hiccup. I got the entire contents of the /wp-content/uploads directory shifted across with no headaches. My next task was to design the new site in a development environment I’ve hosted with my provider.
I was finally happy with the design and fairly confident that all of the content from the original site had carried over. The client was satisfied, and we were ready to migrate hosting and roll out the new design all in one shot. I set to work, and within a few hours (most of which was waiting for the site content to upload via FTP) everything was in place.
Cue the singular issue for this WordPress installation transfer: All of the featured images I had inserted were displaying just fine, and so the theme seemed fine on its face. However, when I started sampling random posts to ensure proper formatting I discovered that all of the post images were broken. The src attributes specified in the img tags were pointing to URLs belonging to the development box.
What’s a monkey to do?
I logged into the phpMyAdmin interface for the new database server and issued a single command:
- UPDATE wp_posts SET post_content=(REPLACE (post_content, '{old url}','{new url}'));
UPDATE wp_posts SET post_content=(REPLACE (post_content, '{old url}','{new url}'));Where {old url} was ‘peaceengine.com/blog’ and {new url} was ‘peaceengine.com’ without the ‘/blog’. And, viola! Just like that I fixed the broken image links in 175 images across 104 posts.





Thanks, easy and fast! ;)
(I used /blog/wp-content/ as url to be sure changing only image and not links)
Hi Sborsch
Your knowledge looks ot be greater than mine fron what you have done
No one's a dork in this game, just loads of patience required. I had a lot of really helpful advice from this site. It's been a while since i had this problem and indeed other problems on other sites I have built since then (4 more) but even being new to Wp there are problem trends.
Have you checked the permalinks, change the settings and then change back
Find and replace can be done in a number of ways via one of the apts plug in's, notepad +, or code. I found apt plug in and notepad + really helpful and remember to add in the full information replacement , if you miss a / out you're buggered.
I had another site I had this on and like you I tried literally eveything, in the end withover 300 photo's I had to manually change every link.
If all fails hit the contact me link above as help is always on hand.
Curious about what happens when -- like a dork -- you do what I did: use the Search and Replace plugin to change all instances of my old http://domain.com to http://domain.com/subdirectory and now all thumbnails are broken.
Been searching and searching tonight for a clever solution to fix the postmeta and somehow, like I do in Mac OS X when I 'repair permissions' and fix the symbolic links, to re-associate the post with the images (even the gallery thumbnails are missing). Seems that serialization is the problem since the associated postmeta has numeric identifiers that look for domain.com and not domain.com/subdirectory
Any thoughts?
@sborsch you've clearly gotten far enough to realize that wp_postmeta is where the thumbnail data are stored. do you have access to phpmyadmin with your hosting arrangements?
Same issue but the above fix didn't work, any ideas?
thanks
@southernboyuk We ended up communicating by email. The fix which ultimately worked for you was to get a dump of your database using phpMyAdmin and run a search/replace in Notepad+ to replace every instance of your old URL with your new URL before dropping the target database and re-creating it.
Anyone interested in a similar process can check out this post for more information on how to use phpMyAdmin: http://www.craniumstorm.com/how-to-move-a-wordpress-site/
@jonahs
Only just fixed it, some great help many thanks again - this guys a star.