Are you looking to do a mass search and replace in WordPress database? Whether you want to find and replace a specific text, URL, or an image, 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.
Searching On WordPress Database
Typically, there’s no way to search and alter your WordPress database from within your dashboard. That’s by design because the DB is the nerve-centre of your website. Everything is stored there, from usernames, emails, to the web address and WooCommerce API keys and tokens. The DB is important. And being able to edit it all willy-nilly is dangerous.
Normally, you need to edit database tables through a tool like phpMyAdmin. In general, you can find this in the cPanel of your host under, you guessed it, databases. Once inside, you have a smorgasbord of options and tables and numbers and tabs and…well, you can see for yourself.
All of those to the left are databases for your host, generally representing one WP install each. And then when you click into one of those, you see all the options you have for all the different kinds of data being stored. And now, you hit Search, and you see the data in that table. Now you can start with the finding and replacing.
That’s a…lot. And it is really easy to get baffled and confused and completely turned around like this. So, the Better Search and Replace plugin may be a good answer for you if you need to edit, change, or migrate any kind of data in your database. This is where our free and easy plugin solution comes in!
When you install the plugin from the WordPress plugin repository, you get a new settings menu that appears under Tools called Better Search Replace.
Inside this new addition, you get a much friendlier user interface than phpMyAdmin. And the best part is that this plugin limits the database to this WordPress installation. So there are no fears of affecting any other sites. There are three main things here to pay attention to.
Pretty straight-forward, really. Whatever values you’re looking for, no matter which table (or how many), are going to be entered here. For instance, if you’re going to edit all comments that contain the name of a particular website you don’t want to be mentioned, you can enter the website name in the first field, and the redaction would go in the second.
Depending on the depth and breadth of your search, you can choose which tables you want to alter. For instance, if you are only looking to alter the comments areas, you can select the ones labelled with comments and comments met with a CTRL/CMD click.
I think this is the most important option they give you. Since the database is so sensitive, performing a dry run gives you a simulation or what would happen. Just enter your info and keep this checked to get a report on which tables and which fields will be changed. It is imperative (if you ask me) to do this first before you make any permanent changes to your site.
Using the Plugin
Using the plugin itself is really simple. For an example, I will walk you through changing a WordPress administrator username. Yes, the same kind of username that comes defaulted as admin or has a warning beside it in the profile that says it can’t be changed. This is the kind of use-case for DB manipulation that makes Better Search and Replaces shine.
First off, you can see the list of users for the WP site.
My goal is to change Nolan Sorento’s username from The Top Dawg to IOI-655321. By doing so, he will log in using the replacement, and anywhere that the username was used in the site will be replaced as well.
I am, highlighting all of the tables with a CTRL/CMD-click, entering my search and replace terms in the fields, and, making sure that I do a dry run first.
As you can see, the only instances of the original username were in users and usermeta tables. Perfect. Now, uncheck the dry run and perform the real search and replace. Afterwards, you will see in the banner that the cells were actually updated, which is verified in the modal, too. Additionally, you can see that instead of .001 seconds, the operation tool 0.004 and 0.003 seconds, so you can tell there was actual computation happening behind the scenes.
When we go back to the Users page, you can see the change has taken hold and the username is completely new.
You can even go into the user itself and see that the greyed outfield has been changed. Usernames cannot be changed, huh? I’ll show you, WordPress documentation!
I think that’s a much nicer, more elegant way of working with your WordPress databases. You can use this for any number of changes that you want to make, including web addresses (changing all file locations away from localhost.dev to elegantthemes.com, for instance). Being able to understand and work with the WordPress database is essential for you to really grow as a developer (and I’d say, user, too). But some of the tools out there are pretty intimidating. Hopefully, Better Search and Replace has shown you that there’s no reason whatsoever to be intimidated.