Tag Archives: search and replace

Moving WordPress: Database Search and Replace Script Software & Sites 28 MAY 2014

If you’ve ever moved a WordPress site to a different domain then you know it is somewhat of a headache. First you copy over all of the files, then you create a database sql dump of your existing database and import it into the new location, make the necessary changes to the configuration file, and then probably curse when you realize that not all your plugins and themes are working correctly any more.

The problem is that obviously one has to do search and replace operations on the database to ensure that all references to the old domain is switched to the new domain, but given the different serialization storage formats used by various third party bits of code, well simply put, it is easier said than done.

Enter this fantastic database search and replace script written in PHP by the guys over at interconnect/it.

You simply download the zipped script, extract the folder to an area in your WordPress location, and then directly access the newly created folder via the browser – the slick AJAX-driven user interface asks you for the search and replace terms, gives you already filled in database connection information (it’s pretty good at picking this up from your WordPress install), and then lets you run off with either a dry run or live execution. Slick, painless and very effective.

Delete the folder when you’re done, though the script even offers to try and do it on your behalf as well! Well written, user friendly, and highly recommended for whenever you find yourself having to change domains for your WordPress site.

thematic-wordpress-tutorial

Related Link: Database Search and Replacement Script

WordPress: Search and Replace Post Text CodeUnit 05 DEC 2009

wordpress-logoNow that I’ve moved all my blogging onto the WordPress platform, I have to begrudgingly admit to it being pretty damn cool after all. However, there are a few quirks and missing bits of functionality that I find bemusing and this seems to be one of them:

There doesn’t seem to be an easy way for searching for and replacing with specific bits of text across all your posts.

Surely this is an essential feature to have don’t you think? Now I haven’t come across a plugin that does this efficiently yet either, so I’ll just point you in the direction of doing it yourself using some plain old SQL, naturally assuming that you have access to your database with some sort of tool like phpMyAdmin for example.

The SQL statement you need to run looks like this:

update wp_posts set post_content = REPLACE(post_content, "X", "Y");

where wp_posts is the name of the table that holds all of your posts (this is the default name), X is what your want to replace and Y is what you want to replace X with.

And that’s it. Modify the SQL statement to look how you’d like and then run it, simple as that! :)

Note: As always, use with caution and at your own risk – always backup your posts table first!