close
findandreplace

If you want to do a mass search and replace in then you can easily do it by using a WordPress plugin or a simply SQL query. Whether you want to find and replace a specific text, image or URL. This article will show do that.

When You May Need Find & Replace for WordPress Database?

Let suppose that you have added specific text or URL to number of your posts. You can’t recall which posts you have added that text to bu there were a lot of them.

You can always do this manually but that’s going to take a lot of time and chances of error are also high. Using a single command to automatically find and replace will do the same thing but much quicker and efficiently. There is one downside to it 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.

Getting Started

As we mentioned earlier that the changes you make to your database will not be reversible. You need to take every precaution to make sure that you don’t lose data.

First you need to create a WordPress database . You can do that by using a WordPress backup plugin. 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.

search-replace-db

It allows you to run search and replace commands from inside your WordPress admin area. We have a detailed guide on how to search and replace in WordPress with 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 login to cPanel dashboard of your WordPress hosting. Scroll down to the database section and then click on phpMyAdmin.

phpmyadmin

The screenshot above is showing 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.

phpmyadminsql

You will need to enter your SQL query in this format:

1update TABLE_NAME set FIELD_NAME =
2replace(FIELD_NAME, ‘Text to find’, ‘text to replace with’);

 

You would write your query like this:

1update wp_posts set post_content =
2replace(post_content,’Text to find’,’text to replace with’);

 

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.

 

Tags : find and replacewordpressWordPress how to
Nooruddin Ahmed

The author Nooruddin Ahmed

An avid football fan. Lives for the weekend game.Aviation enthusiast. Believes in letting bygones be bygones.

Leave a Response