Are you looking to do a mass search and replace in WordPress?
Whether you want to find and replace a specific text, URL, or image on your WordPress website, you can easily do so by using a find and replace WordPress plugin or a simple SQL query.
In this article, we will show you how to find and replace text in your WordPress database.
When Do You Need to Find & Replace in the WordPress Database?
There are a few scenarios when you might need to find and replace items within the database of your WordPress website.
For example, let’s suppose that you have added specific text or URLs to a number of your posts. You don’t know which posts you have added that text to, but you do know that there are a lot of them.
Now, you can manually search your site and edit every single post one by one. But that’s going to take a lot of time and has a high chance of you missing some of the text you want to change.
Using a single command to automatically find and replace the items will do the same thing but much quicker and more efficiently.
There is one downside to this method, though. If you made a mistake, then you will not be able to undo it. Once you replace the text, it is gone. You will need to carefully type the text you are looking for and the text you want to replace it with.
Having said that, let’s see how you can easily find and replace text in your WordPress database.
Before Running Search and Replace on Your Database
As we mentioned earlier, the changes you make to your database will not be reversible. You need to be very careful to make sure that you don’t lose data.
Alternatively, you can also create a database backup using phpMyAdmin.
After creating the backup of your WordPress database, you can move on to run your find and replace commands.
Running Find and Replace With a WordPress Plugin
If you are not familiar with code and don’t want to write a custom SQL query, then there is an easy-to-use find and replace WordPress plugin called Better Search Replace.
First, you need to install and activate the Better Search Replace plugin. For more details, you can see our guide on how to install a WordPress plugin.
Then, you need to go to Tools » Better Search Replace in your WordPress admin dashboard.
From here, you need to enter the text you want to change into the ‘Search for’ field. You must then write the text you want to replace it with into the ‘Replace with’ field.
You also have the option to select specific tables within your WordPress database.
In the ‘Additional Settings’, we also recommend checking ‘Run as dry run’. That way, the plugin will allow you to check the changes it will make before it applies them.
Then, simply click on ‘Run Search/Replace’.
If you need more help, we have a detailed guide on how to search and replace in WordPress with a Better Search Replace plugin.
Running Find & Replace MySQL Query with phpMyAdmin
You can also use phpMyAdmin to find and replace text from your WordPress database.
First, you need to log in to the cPanel dashboard of your WordPress hosting account. Then, scroll down to the Databases section and click on ‘phpMyAdmin’.
The screenshot above shows the cPanel dashboard on Bluehost. Your cPanel dashboard may look slightly different.
This will launch phpMyAdmin, where you will need to click on your WordPress database name and then click on ‘SQL’.
You will then need to enter your SQL query in this format:
update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, 'Text to find', 'text to replace with');
For example, if you wanted to search for text in a WordPress post’s content, then you would write your query like this:
update wp_posts set post_content = replace(post_content,'Text to find','text to replace with');
Then, click on the ‘Go’ button to continue.
phpMyAdmin will run your SQL query, and upon success, it will show the number of rows affected by the query.
You can now visit your WordPress site to see your changes in action.
We hope this article helped you learn how to find and replace text with one click in your WordPress database. You may also want to see our beginner’s guide on WordPress database management with phpMyAdmin and our expert picks of the best WordPress database plugins.