arrow-left arrow-right brightness-2 chevron-left chevron-right facebook-box facebook loader magnify menu-down rss-box star twitter-box twitter white-balance-sunny window-close
WordPress find and replace
1 min read

WordPress find and replace

As much as I like WordPress, I’m still a little miffed from time to time by its shortcomings. Of all the things it should have, it’s missing a simple find/replace function. I’m not sure any excuse the WP team could come up with would make sense to me — this is not a feature, but rather a necessary tool.

As is the case with most things in life, there is a workaround (that requires very little SQL knowledge). To find/replace something in WP, all you really need is the following query:

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

Where wp_posts is the name of the table that holds your WP posts (wp_posts is the default), X is what you want to replace, and Y is what you want to replace X with. You can obviously run this query directly or through phpMyAdmin if you have it setup (just click the SQL tab once you’re inside your database). Simple, right? Right, which is why I can’t figure out the reason it’s been left out of WP.

Future Plugin

I was a little suprised to come up empty when looking for a find/replace plugin (surely everyone needs/wants this?). I think I’ll probably write a plugin for this in the next couple of months if no one else does.

UPDATE: I’ve been told that there is a plugin to do this: Search and Replace. I might still write my own plugin that supports regex pattern-matching.

You've successfully subscribed to Justin Blanton.
Success! Your account is fully activated, you now have access to all content.