was successfully added to your cart.

How to Search and Replace your WordPress Content in MySQL

I love “Search and Replace” functions – I use them all the time in Excel, Word, and Notepad. Sometimes we wrangle a LOT of data, so being able to make these quick changes is a real time saver.

search and replace wordpress

Something we’ve been talking about with clients lately is also doing Search and Replace in a WordPress database – using MySQL.

Search and Replace within your WordPress website

This is incredibly handy if you have bulk updates to make across a big WordPress site – changing dates, links, html, or even just a few words. You can get it all done in one go, without having to edit 20+ pages or posts.

The caveat is that you need access to your MySQL database, via PhpMyAdmin. And you do need to know what you’re doing in here – it’s not for the faint hearted as one wrong step could break your website.

No pressure guys…

Step by step Search and Replace for WordPress

So first of all:

BACKUP YOUR DATBASE.

Then, to Search and Replace content within WordPress posts or pages:

  1. Choose your database
  2. Click on the SQL tab
  3. Write the command you want in the text area (see how to do this below)
  4. Double check everything
  5. Hit “Go”
  6. Check the front end of your WordPress site to make sure it worked and didn’t break anything!

Here’s what you need to write in to perform WordPress Search and Replace:


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

The “Item to replace here” text needs to be EXACTLY what you want to replace. Remember this function is looking for a direct match If there’s an extra space or bit of punctuation, it won’t work.

Please Please Please

Please take care when you do this – it is very powerful and can quickly replace an hour’s worth of work. It can also break your site if you mess it up, so proceed with caution.

Give us a bell if you want to do this and think you might need a hand.

Contact SiteSmart