wordpress development

When you build a blog or site using WordPress, you usually develop it in a subdiretory of the domain where it will ultimately reside or on a completely separate development server with a different domain or even just an IP address.  When you first install WordPress in your development environment, you have to tell it the URL where it will reside even though this will change when the site is pushed live.

There’s a handy step-by-step guide in the documentation for moving your WordPress installation to a new server.  The usual stuff is covered.  Back up your database, replace any hard-coded references to the development URL in your template files, move the files to the new server, edit your config file with any appropriate changes to the database credentials, etc.  But there is one thing in particular that isn’t mentioned.  All the hard-coded references to the development URL that are stored in the database.

You’ll probably have posts or pages with uploaded images and links to other pages within the blog.  WordPress will store all of these in the database with your development URL.  Most people, myself included, won’t feel like going through all of your posts and pages manually to update any references to your development URL.  When researching this problem, I came across a really helpful solution and wanted to share it.

You’ll need access to the database to execute some SQL that will find and replace all references to the development URL with the new production URL that you provide.

UPDATE
   wp_posts
SET
   post_content = REPLACE(post_content, "www.dev-url.com", "www.live-url.com")

You need to execute a similar statement for a few other fields in the database:

wp_posts.guid
wp_options.option_value

Additionally, if you have any custom fields associated with posts or pages, you’ll want to do the same update on:

wp_postmeta.post_value

Check the database for tables used by any installed plugins.  You may need to update fields in those tables as well.

Even though you have to scan and examine the database, this method is much faster than updating references manually.

Leave a Reply