Find and replace text across a whole WordPress web site using phpMyAdmin

You can do a find and replace for text or html code on a post or page across a whole WordPress site by using the mysql database that the site stores all its data in.

First up you need to connect to the database, if you have a cPanel/Plesk style hosting typically you will have an option to connect to the database via phpmyadmin.

Connect to your WebHost

connect-to-phpmyadmin

Launch phpMyAdmin

 Select Your WordPress Database

select-wordpress-database

Select your WordPress database

If you have multiple databases and don’t know which one, check the database name in the wp-config.php file which is stored in your webroot; htdocs or public_html

Select the wp_posts table

select-wp-posts-table

Select the wp_posts table

To Search For a Text Query Only

Select SQL Tab and add in the Search Query SQL Code

input-search-string

SELECT * FROM wp_posts WHERE (post_content LIKE '%TEXT-TO-FIND-GOES-HERE%');

Click ‘Go’

search-for-text-mysql

To edit the post, click on edit and do what needs to be done – if you edit the text it will be updated in your WordPress post.

To Search and Replace For a Text String

Select SQL Tab and add in the Search and Replace SQL Code

find-and-replace-text-in-wordpress

Add in the find and replace SQL code

 

So here switch to the ‘SQL’ tab add in the code below and click on the ‘Go’ button.

UPDATE wp_posts SET post_content = REPLACE (  post_content,  'text to find here',  'text to replace here');

So with the SQL code you put your text between the single quotes for what you are finding and what you are replacing these are separated by the comma.

See the Results

phpmyadmin-shows-how-many-rows-are-affected

Shows you how many instances the find/replace occurred

Doing it via Command Line

This can also be easily done via the command line, you just need to start a mysql session:

mysql -u username -ppassword
use mywordpress_table;
UPDATE wp_posts SET post_content = REPLACE (  post_content,  'text to find here',  'text to replace here');

Doing it with a Plugin

phpMyAdmin and Command Line – fill you with dread? – never fear a plugin is always handy….

11 Comments

  1. drhoseinisianaki on December 14, 2020 at 7:39 pm

    hi thanks for sharing this useful post very helpful, me translated that to my language.

  2. Ricky on December 30, 2017 at 4:56 am

    Hi,

    How can delete everything after a certain keyword in post_content?

    For example:
    Name: Ryan
    Age: 24
    keyword
    text to be delete
    text to be delete too

    Result:
    Name: Ryan
    Age: 24

    Thanks

  3. David on November 3, 2016 at 7:58 pm

    IMHO, a MUCH better plugin solution is here: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/

    (I’m in no way connected with them)

    I use it all the time and it works brilliantly and is a real lifesaver when dealing with serialized (JSON) data.

    • Neil Gowran on November 6, 2016 at 8:42 am

      Yes I use this too, it’s an important tool – but this guide is also for users to get acquainted with phpmyadmin

  4. سئوکار on July 8, 2016 at 7:53 am

    Thank you
    You are best :)

  5. bestgasht on April 11, 2016 at 10:03 am

    Thanks. I use It.

  6. quan on November 13, 2015 at 7:17 am

    thank you very much!

  7. Anto on April 15, 2015 at 9:47 am

    Great help many many thanks!

  8. darknote on March 22, 2015 at 3:14 pm

    Hi,
    How to remove the slash between the french words, for example “l\’été”
    Thank you

  9. Andre on January 27, 2015 at 3:04 pm

    Thanks for the post. It worked like the charm. However, when I tried replacing the guid column also, it removed all the content on my wordpress site…

    But besides that, it all worked well.

  10. member0123 on January 14, 2015 at 2:26 pm

    Thank you, that’s really east to follow post, but most important thing to consider before updating database, is to make a backup, in-case you mess up something. hope you update post and remind people .

Leave all Comment