Search and Replace in WordPress

Last night I upgraded my blog CMS to WordPress 2.7. It should have been simple; it should have taken less than five minutes. I won’t bore you with the details. The problem was that an index.php file wasn’t replaced by the FTP client which completely broke the site.

As a result of the frustrations and troubleshooting I decided to go ahead and move the root to a different folder on the server. It had been in /brent/wp_blog which was superfluous: nothing else was in /brent.

Moving the files was a simple drag and drop in the FTP client. The drawback was that it broke pictures and links looking for ‘wp_blog/’ in 228 posts. I needed a search and replace or I would be doing it manually all day.

Lorelle on WordPress came through again with her post about doing just what I needed. The solution was a simple MySQL UPDATE query on the wp_posts table.

UPDATE wp_posts SET post_content = REPLACE (
post_content,
'wp_blog/',
'');

In 0.0158 seconds 196 posts were updated. Pretty cool, eh? No more broken internal links.

Unfortunately, all the links to The Rhetoric content across the interweebs are now broken, but that shouldn’t be many. The upside is that the document tree is cleaner and more simple.

Perhaps now I should run queries to update style selectors so I don’t have to keep hanging on to legacy declarations. Hmmmmm.

3 Comment

  1. Always glad to help. This is so annoying. There used to be a Plugin that did this from the WordPress Administration Panels, but it doesn’t work now. We often have to search and replace something across all our posts, and this way works, but I wish it was easier.

    Glad it worked for you!

    1. @Lorelle – I’m honored you took the time to comment. I’ve used your tips several times. Your explanations and examples are very well written and your humour entertaining.

      Cheers.

      @Steven – Sorry mate. :)

  2. Hey, what are you talking about? My site is chock-full of links to the The Rhetoric. All my hard work is ruined thanks to your silly workaround!

    Thanks for the search & replace tip, though.

Leave a Reply