How to Find and Replace Text with One Click in your WordPress Database

Posted on August 4th, 2009 by in Tutorials | 3 Comments  
How to Find and Replace Text with One Click in your WordPress Database

There are times when you have a blog that has 400 posts, and you decided to switch your domain and you were using write-in images for your thumbnails in the custom field. Now you have a huge problem because you need to go and replace each image URL to the new URL. Or lets say you wrote 50 posts and you spelled something wrong. For example WordPress instead of WordPress. Now you can’t possibly go search all 50 posts to change just the uppercase of P. In this post we will show you how you can use an SQL Query for WordPress Database to Find and Replace text with just one click.

Find and Replace Text

You need to go to your phpMyAdmin and select your database. Then click the button SQL. Once you have done that paste the following code:

update TABLE_NAME set FIELD_NAME =
replace(FIELD_NAME,’TEXT TO FIND’,'TEXT TO REPLACE’)

This will work with any MySQL Database not just WordPress. Make sure that you make a backup of your database before you run this query.

In the example, we will be replacing the text WordPress to WordPress in our posts.

update wp_posts set post_content =
replace(post_content,’Wordpress’,'WordPress’)

Hit Done, and all will be replaced with one click. This is very helpful, and it can save you a lot of time.

Just please make sure to make a Backup of your Database.

About

Editorial Staff at WPBeginner mainly Syed and David.

Post comment as twitter logo facebook logo
Sort: Newest | Oldest
susanlivefyre 5 pts

It looks like you did such a great job of updating that in your "before" example "WordPress" looks like "WordPress" I can't tell the diff. ;)

Perfect, just what I was looking for :o)

Thanks! I was looking for this! My wife has a music blog, she pulls MP3s from another website (which allows file embeding for online listening), they change IPs frequently, resulting into error on other sites which embeded their files. Your code will come to use in situation like these, we can change the IP via SQL very easily.

Tweets about us: