At some point, you’re going to want to change your WordPress site around a little. It might be just a simple theme change or maybe it’s a full transfer of your site from one host to another — or from a local installation to a live one. Maybe you’ve swapped URLs from a .com to a .design. You might even need to change a user’s username or any number of other values. Doing these things manually can be a huge pain and a massive time sink. Thankfully, there’s an easier way. In today’s post we’ll show you how to use a free plugin to get the job done quickly and easily.

Search and Replace, The Old Way

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-center 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.

Better Search and Replace Plugin for WordPress Database

Once inside, you have a smorgasbord of options and tables and numbers and tabs and…well, you can see for yourself.

Better Search and Replace Plugin for WordPress Database

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.

Better Search and Replace Plugin for WordPress Database

And now, you hit Search, and you see the data in that table. Now you can start with the finding and replacing.

Better Search and Replace Plugin for WordPress Database

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!

Search and Replace, The Better Way

Better Search and Replace Plugin for WordPress Database

When you install the plugin from the WordPress plugin repository, you get a new settings menu that appears under Tools called Better Search Replace.

Better Search and Replace Plugin for WordPress Database

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.

Better Search and Replace Plugin for WordPress Database

1. Search For / Replace With

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 mentioned, you can enter the website name in the first field, and the redaction would go in the second.

2. Select Tables

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 labeled with comments and commentsmeta with a CTRL/CMD click.

3. Run as Dry Run

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.

Better Search and Replace Plugin for WordPress Database

Using the Plugin

Using the plugin itself is really simple. For an example, I will walk you though 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 Replace shine.

First off, you can see the list of users for the WP site.

Better Search and Replace Plugin for WordPress Database

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

  1. highlighting all of the tables with a CTRL/CMD-click
  2. entering my search and replace terms in the fields, and
  3. making sure that I do a dry run first

Better Search and Replace Plugin for WordPress Database

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. Afterward, 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.

Better Search and Replace Plugin for WordPress Database

When we go back to the Users page, you can see the change has taken hold and the username is completely new.

Better Search and Replace Plugin for WordPress Database

You can even go into the user itself and see that the grayed out field has been changed. Usernames cannot be changed, huh? I’ll show you, WordPress documentation!

Better Search and Replace Plugin for WordPress Database

And There You Have It

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.

What is your preferred method of database manipulation?

Article featured image by hanss / shutterstock.com

The post How to Better Search and Replace Values in your WordPress Database appeared first on Elegant Themes Blog.



Source link

error: Content is protected !!