1. Home
  2. Applications Management
  3. WordPress
  4. How to Perform a WordPress Search and Replace

How to Perform a WordPress Search and Replace

Managing a busy WordPress site shouldn’t be a burden. Sometimes you may need to make some minor changes which only take a few minutes, but other times you may find yourself updating a LOT of assets on your site one after the other, a task that you should automate to make your life easier.

WordPress calls this a Search & Replace.

Other circumstances in which you may find a Search & Replace to be very useful are if you migrated from HTTP to HTTPS or have recently changed your domain name.

In this Knowledge Base article we will cover how to do a WordPress Search & Replace using 3 easy methods!

Let’s go!

How to Perform a WordPress Search and Replace Using a Pugin (Better Search Replace)

The Better Search Replace plugin is a fantastic choice and my go-to plugin when it comes to performing a search and replace for a lot of items. The plugin is free and from the noted WordPress plugin developers over at Delicious Brains (mmm 🧠🧠🧠). The plugin consolidates a lot of features from other plugins into one plugin and supports the following features:

  • Serialization support for all tables.
  • The ability to select specific tables.
  • The ability to run a “dry run” to see how many fields will be updated.
  • No server requirements aside from a running installation of WordPress.
  • WordPress Multisite support.

With the Pro version you get these additional features:

  • View exactly what changed during a search/replace.
  • Backup and import the database while running a search/replace.
  • Priority email support from the developer of the plugin.
  • Save or load custom profiles for quickly repeating a search/replace in the future.
  • Support and updates for 1 year.

Step 1: Download, install and activate the Better Search Replace plugin by navigating to your /wp-admin > Clicking Plugins > Add New and searching for Better Search Replace.

Once the plugin is installed, click Activate to enable Better Search Replace.

You will be returned to your Plugins area where you will see all of your plugins.

Step 2: To open Better Search Replace, hover over Tools on the left side and in the little menu which appears click Better Search Replace.

Step 3: When the Better Search Replace page opens, you will see you have a few options. Let’s examine them.

  • In Search for you have will enter the text you want to change.
  • In Replace with you will enter the text that will replace the original text.
  • In Select tables you would select the tables you want Better Search Replace to query and update.
  • Case-insensitive means Better Search Replace won’t care if you are searching for chemicloud or ChemiCloud.
  • Replace GUIDs should generally be left alone. Please see the important note below regarding this.
  • Run as dry run will just run the query and search, but no updates or changes will be made.
Important information:

When doing the above and changing the URLs directly in the database, you will come across instances of the URL being located in the “guid” column in the wp_posts tables. It is critical that you do NOT change the contents of this field.

The term “GUID” stands for “Globally Unique Identifier”. It is a field that is intended to hold an identifier for the post which a) is unique across the whole of space and time and b) never, ever changes. The GUID field is primarily used to create the WordPress feeds.

When a feed-reader is reading feeds, it uses the contents of the GUID field to know whether or not it has displayed a particular item before. It does this in one of various ways, but the most common method is simply to store a list of GUID’s that it has already displayed and “marked as read” or similar.

Thus, changing the GUID will mean that many feedreaders will suddenly display your content in the user’s reader again as if it was new content, possibly annoying your users.

In order for the GUID field to be “globally” unique, it is an accepted convention that the URL or some representation of the URL is used. Thus, if you own example.com, then you’re the only one using example.com and thus it’s unique to you and your site. This is why WordPress uses the permalink, or some form thereof, for the GUID.

However, the second part of that is that the GUID must never change. Even if you shift domains around, the post is still the same post, even in a new location. Feed readers being shifted to your new feeds when you change URLs should still know that they’ve read some of your posts before, and thus the GUID must remain unchanged.

Never, ever, change the contents of the GUID column, under any circumstances.

For my Search and Replace, I want to change the references to posts that contain the term cchosting to ChemiCloud. To do this, I’m going to configure my settings as follows:

After clicking Run/Search Replace, I can see it was successful and updated the references to cchosting in my posts database to ChemiCloud:

Success! And that is how you use Better Search Replace plugin to update content on your website quickly and easily!

How to Perform a WordPress Search and Replace Using the wp-cli

WP-CLI is a set of command-line tools for managing WordPress installations, without using a web browser.

ChemiCloud’s WordPress hosting infrastructure supports WP-CLI out of the box.

Step 1: Open up an SSH connection to your hosting account. If you are not familiar with how to do this, please review our KB on the topic here.

Step 2: Once you are connected via SSH, you would use the following command to perform a search and replace:

wp search-replace 'original text' 'new text' --skip-columns=guid

By default, the search-replace command does the tables registered with $wpdb. You may have some custom tables that also need to be updated and then the –all-tables flag is very useful.

wp search-replace 'original text' 'new text' ---skip-columns=guid --all-tables --recurse-objects --precise

Note, we are using the flag –skip-columns=guid to ensure our GUIDs are not modified.

–preciseForce the use of PHP (instead of SQL) which is more thorough, but slower.
–recurse-objectsEnable recursing into objects to replace strings.

If you want to run a test query without actually making changes you can add –dry-run parameter.

For more commands and examples for tasks, you can perform using wp search-replace, reference the official documentation on the subject here.

Are you tired of slow WordPress hosting? We use LiteSpeed caching to deliver content to your visitors almost instantly. ⚡ Check out our WordPress Hosting plans!

How to Perform a WordPress Search and Replace Using phpMyAdmin


Before using this method, be sure you create a backup of your WordPress Database in case you make a mistake. If you are not familiar with how to do that, please reference our KB article on that here.

Step 1: Log in to your cPanel. There’s a lot of ways to do this, but the sure-fire easiest way is to log in to your Client Area, then open your cPanel.

Step 2: Under the Databases section, click phpMyAdmin to open the utility.

Step 3: Once phpMyAdmin is open, click on the database containing your WordPress installation on the left to select the database.

The list of tables in the database will be displayed to indicate the database has been selected.

Once you have selected the database for your WordPress installation, click SQL at the top of phpMyAdmin.

Step 4: Once you have clicked SQL, the phpMyAdmin app will display a text box which looks very much like the one below:

You can think of this text box as a console, similar to SSH. Using valid mySQL commands, you can make changes to your database tables and content within the tables with ease.

The commands you want to use to perform a search and replace via the SQL command line is as follows:

update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, 'Text to search for, 'Text to replace it with');

Simply update the appropriate areas of the command with the right table name, field name, and the text to search for and replace with, then press return on your keyboard to run the command.

When the process is finished, and depending on the amount of changes you are making, it could take a few minutes, you will see a message indicating the number of instances updated or changed. You can then visit your WordPress site to make sure the changes have been made successfully!

If you enjoyed this tutorial, then you’ll love our support! All ChemiCloud’s hosting plans include 24/7 support from our amazing support team. Check out our WordPress hosting plans and have your website migrated today!

Updated on April 5, 2022

Was this article helpful?

Related Articles

Tired of struggling with troubleshooting? 🤔
If you enjoyed this article, you’ll love our support team even more! Get up to 65% off and a FREE Domain for a limited time. 👇
View Plans

Leave a Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.