February 10, 2012

Replace embedded post links after changing domains

And now for a short SQL lesson in a case study.

Ever do this? Map a domain to a sub-blog, post away merrily for a while (or a user does) and then one day decide you like another domain name better? Yeah. I hate when that happens. Usually because I get to fix it.

No problem! We just re-map the new domain and we’re good to go. But wait! Now all our images embedded in posts have gone *poof*. I mean, they’re still there on the server, but now we have link in posts with absolute URLs pointing to the old domain. Bummer.

Open up phpMyAdmin or whatever you use to manage your database. Click on the SQL tab because we’re gonna run a query. The query below, in fact.

update `wp_BLOGID#_posts`
set `post_content` = replace(`post_content`,’olddomain.com’,'newdomain.com’)

The above basically says in the posts table of this particular blog, change all instance of olddomain.com to newdomain.com. make sure you get the right blog ID # of the blog in question.

Get 3 for the price of 2 in the Network Home Bundle

Includes 3 ebooks with plugins -
Network Home Pages: aggregate global content, set up sitewide tags, create a huge tags cloud like the one seen on WordPress.com, global footers and menus, setting defaults & more
Custom Registration: sign up on sub sites, multilingual signup pages, stop spam blogs
WP Curator: pick and choose posts from sub sites to feature on the main home page of your network

Network Home Pages, Custom Registration & WP Curator – $35.90 for all three. Purchase

Comments

  1. E Bryant says:

    I thought WP made relative links, and renaming a domain just needed to update your wp_options table?