How to find Replace Text in WordPress Database? 2 Different Methods

There are certain reasons why you need to find and replace in WordPress. We have explained two different ways to find and replace text in WordPress Database.

Many beginners don’t how to do find and replace in WordPress Database, whether it is specific text, URL or an image. There are certain reasons why you need to find and replace in WordPress. So if you are looking for how to find and replace in WordPress database then here we have explained 2 different ways. With that, you can easily find and replace in WordPress.

In Which Case You Need To Find & Replace for WordPress Database?

In a case, you want to replace the specific text that you added in many of your posts and you don’t remember that how many posts there are, which contain that specific text. At that time you need to do find and replace in WordPress.

It is very hard to find by looking at one by one post and manually replace text in those all posts. It also takes too much time and sometimes you may miss some occurrence.

But using two different methods 1) Using Plugin and 2) Using MySQL, you can easily, quickly and automatically find and replace that specific text in WordPress. But be careful while you are typing the text. Because once you replace the text then you can’t undo it, if any mistake with the text.

The Most Important WordPress Database Backup

As I have stated before that you can’t undo the text once you replace it. So it is very important that you must create a backup of your WordPress database before you perform the task of find and replace text in WordPress. There number of automated WordPress database backup solutions available.

Read this post: The Most Useful WordPress Databse Backup Plugins For Automated Backup

Or

Read this post: How to take WordPress Database Backup Manually: 2 Different Methods

Once backup of your WordPress database is done, you can perform the task of Find and Replace Text. So let’s see how to find and replace text in WordPress with the help of plugin and MySQL query.

Using Plugin To Run Find and Replace Text in WordPress

To find and replace text in WordPress, there is an outstanding plugin available called Better Search Replace. If you are not used to with code or SQL query then this WordPress plugin will be the most helpful to find and replace text in WordPress.

Better Search Replace Plugin To Run Find and Replace Text in WordPress

Better Search Replace plugin performs replacement actions without damaging PHP serialized strings or objects. It also offers you to run find and replace task inside your WordPress admin area.

Using MySQL Query To Run Find and Replace Text in WordPress

Performing find and replace action in MySQL is little bit tricky, but easy as well. You will require little bit knowledge and understanding of a couple of MySQL queries.

To perform the action you will require to access the phpMyAdmin area of your website under database section.

For the first time user, follow this steps to access phpMyAdmin area.

  • Login to the cPanel of your WordPress Hosting.
  • Navigate to Database Section.
  • Under Database, click on phpMyAdmin icon to access.

This will take you to the phpMyAdmin homepage.

phpMyAdmin home screen

Now, click on your database on the left-hand side and click on SQL tab,

MySQL in phpMyAdmin

Run the SQL query in this format.

MySQL query box

update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘text to find’, ‘text to replace with’);

For an example if you want to replace the text in all post content then you would run the query like:

Update Wp_Posts set post_contnet = replace(post_content, ‘Text to find’ , ‘Text to Replace with’);

With this query, you can also replace a URL in all posts content with SQL query like:

update wp_posts set post_content = replace(post_content, ‘URL to find’, ‘URL to replace with’);

As soon as you hit GO, SQL query will be executed and will show the results that how many rows affected by the query.

Bonus: How to Change or Update URLs in WordPress Database?

To change or update URLs in WordPress Data, four queries needs to run in SQL Query box:

UPDATE wp_options SET option_value = replace(option_value, ‘http://www.OLDdomain.com’, ‘http://www.domain.com’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’;

UPDATE wp_posts SET guid = replace(guid, ‘http://www.OLDdomain.com’,’http://www.NEWdomain.com’);

UPDATE wp_posts SET post_content = replace(post_content, ‘http://www.OLDdomain.com’, ‘http://www.NEWdomain.com’);

UPDATE wp_postmeta SET meta_value = replace(meta_value,’http://www.OLDdomain.com’,’http://www.NEWdomain.com’);

Repalce old domain link and place a new domain or link and run individual query one by one to change or update link in the WordPress Data through phpMyAdmin.

I hope, this article is useful for you and you successfully find the replace the text in WordPress Database.

Share your feedback or query by commenting below.