Over the years, we’ve been asked by many of our readers how to do a mass search and replace in WordPress.
At WPBeginner, we understand the challenges of managing a large WordPress website with tons of content. Whether you’re migrating from an old domain, rebranding, or simply fixing a typo, manually searching and replacing content in every post, page, and comment is nearly impossible.
Luckily, you can easily search and replace text, URLs, and images on your WordPress site by using a find-and-replace WordPress plugin or a simple SQL query.
In this article, we’ll 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, 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 post one by one. But that’s going to take a lot of time, and there’s a high chance you’ll miss 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 make 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.
First, you need to create a WordPress database backup. You can do that by using a WordPress backup plugin like Duplicator.
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’re not familiar with code and don’t want to write a custom SQL query, then there’s an easy-to-use find and replace WordPress plugin called Search & Replace Everything.
First, you need to install and activate the free Search & Replace Everything plugin. For more details, you can see our guide on how to install a WordPress plugin.
Note: There’s also a premium version of Search & Replace Everything that comes with more advanced features.
Upon activation, visit the Tools » WP Search & Replace page in your WordPress admin dashboard.
From here, 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 or select all of them.
Next, press the ‘Preview Search & Replace’ button.
The plugin will now allow you to check the changes it will make before it applies them.
Then, simply click on the ‘Replace All’ button.
If you need more help, we have a detailed guide on how to search and replace in WordPress.
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 dashboard of your WordPress hosting account. For this tutorial, we will be using Bluehost.
Once you are there, click on the ‘Websites’ option from the left column and then switch to the ‘Advanced’ tab.
After that, scroll down to the ‘PHPMyAdmin’ section and click the ‘Manage’ button next to it.
This will launch phpMyAdmin in a new window.
Here, you must 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 the changes in action.
Bonus: Optimize Your WordPress Database Easily
Once you have replaced the desired text in your database, we recommend optimizing it to remove unwanted data and improve your database’s performance.
For this, you can install and activate the WP Optimize plugin. For details, see our tutorial on how to install a WordPress plugin.
Upon activation, visit the WP-Optimize page from the WordPress dashboard. You will now see a list of operations that the plugin will perform on your database. You can review them and uncheck any item that you don’t want to run at the moment.
From here, you can optimize database tables, clean post revisions, draft posts, and more. After that, just click the ‘Run on all selected items’ button at the top.
The plugin will now optimize your database for you. However, if the process is interrupted, it may corrupt data. That’s why we recommend creating a site backup before optimization.
For details, see our tutorial on how to optimize your WordPress database with one click.
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.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
Syed Balkhi
Hey WPBeginner readers,
Did you know you can win exciting prizes by commenting on WPBeginner?
Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
You can get more details about the contest from here.
Start sharing your thoughts below to stand a chance to win!
Dennis Muthomi
PRO tip I’d like to share is:- the importance of testing the search and replace function on a staging site first, especially when dealing with serialized data.
This can help prevent unexpected issues that might arise from replacing certain strings.
Aaron
Thanks for the great tips! Just did the backup before search and replace all in phpMyAdmin without installing any plug-ins. Then installed WP-Optimize to clean up the database. Fantastic!
WPBeginner Support
You’re welcome! Glad our guide was helpful
Admin
kzain
This is a lifesaver for making bulk edits to my WordPress site! While there’s no magic ‘one-click’ solution, the plugin recommendations and the phpMyAdmin approach for advanced users are both valuable. I especially appreciate the reminder to back up the website first, that’s a safety net I won’t skip.
Lisa Dodson
The plugin recommendation would have been better if it didn’t require you to upgrade to see the actual record results instead of just the number. With a lot of posts, I would never blindly never do a mass replace without seeing the detailed results first.
WPBeginner Support
Using the dry run feature should tell you the number of results that are found and would be changed
Admin
Chris
Can do search and replace HTML code? I have snippets of (table td tr) code I would like to replace.
WPBeginner Support
It would depend on where that code was added from, you should normally be able to edit the page that it is on for modifying the code.
Admin
Shahala
Hey there! could you please tell me how can I do this find and replace in sql for a word only in specific language?
I tried using language queries but din’t work out!
I really appreciate any help towards this. Thank you
WPBeginner Support
Unless I hear otherwise, we don’t have a language specific search at the moment sadly.
Admin
Saud Shah
How can we change 2018 to 2019 in categories and page titles with this plugin or phpmyadmin
WPBeginner Support
For the post and page titles, you would search the wp_posts table but, for changing categories and their urls you would want to do that manually and create 301 redirects.
Admin
Aminu
please, how do you replace texts in posts title?
Vishal
Thanks a lot for this. I was looking for the exact same solution.
Anang
Thanks a lot. It saves me hours of work.
RCdiy
I want to replace all instances of “OpenTx” with “OpenTX” but skipping URLs. So basically only what the viewer sees… How do I do this? I’ve installed both Search Replace and Better Search Replace but they also replace in the URLs…
Piter
I tried plugins “Search $ replace” and “Better Search Replace” but there was no effect. Links in my posts was there. But…
Thanks a lot for code metod, it works fine. It takes only few seconds.
samowal
Thank you very much, man.
Peter
You already wrote an article about this last year: https://www.wpbeginner.com/plugins/search-and-replace-plugin-for-wordpress-database/
WPBeginner Support
Thanks for noticing This is actually a rewrite of an old article that only showed the code method. We decided to add the plugin method and more explanation to it.
Admin
KMurphy
Is this something that would work in migrating a site – to change the DB urls to a new location?
Kim Hopkins
I just did this.
Oscar Estepa
I’m not 100% sure but I’d say the SQL query can’t handle serialised data. If you search & replace your database using the suggested SQL query you’ll break the serialised data and get yourself into lots of troubles down the road like widgets not working, images dissappearing, broken javascript, etc.
It’s well explained in this link http://davidcoveney.com/782/mysql-database-search-replace-with-serialized-php/
So better look for a plugin, script or tool which handles serialised data, like the suggested plugin Better Search Replace or the interconnectit script.
Personally I use search and replace tool integrated in WP-CLI, in my experience it’s the best and fastest tool out there, never had a problem so far, tested in dozens of websites. For less savvy people, I’d recommend a plugin since WP-CLI is a terminal command tool and might not suite everyone.
Damien Carbery
I like internetconnect/it’s Database Search and Replace Script.
Unlike the phpMyAdmin example in the article, it will search all fields. It will also do a dummy run.