WordPress search and replace the easy way

By 6th April 2011 November 13th, 2017 Creative, Technology & Business Intelligence
WordPress website

How to quickly search and replace any HTML/text on a WordPress website?

We’ve got a client website that’s about to go out the door in the next 48 hours. The site has got around 75 webpages, and noticed that the copy on one page needs to be duplicated to all other pages. Arrrghh …

Search magnify

Now, we’re running a WordPress setup with multiple sites on all our servers (development, staging and live) and a lot of the WordPress search and replace plugins assume you only have one website/blog.

So … the easy way … stop searching for the perfect WordPress plugin and follow these simple steps

 

  1. Pull up phpmyadmin
  2. Find the correct site/blog you’re wanting to update – in my case, it’s site # 16
  3. Go to the SQL tab and enter the following statement (where wp_16_posts uses the 16 corresponding with the correct site above!) –UPDATE wp_16_posts
    SET post_content = replace(post_content, "Old text here", "New text here")
  4. Now the nice thing is, the replace function can be built up of anything that’s in that post (or anywhere else in the database for that matter, but let’s keep it simple) … for instance –UPDATE wp_16_posts
    SET post_content = replace(post_content, "<h1>Dummy heading</h1>", concat("<h1>", post_title, "</h1>")
    … would take the post title, and replace the h1 Dummy heading text with the post title.

 

Hope that helps someone out there looking for a quick, down and dirty, search and replace for WordPress!