Some helpful SQL


I had needed this before and I had to go out and find it again so I figured I’d post it this time. Here’s a really helpful SQL script that will let you do a “search and replace” within a single column of data in a table. Very, very handy when you need to update inline links (which is what I’m doing in the example below). I had set the default location of where images are saved to a folder called “uploaded_images”. I later changed this to wp-content/images but the old posts still pointed to the old location even though the new posts pointed to the correct location. In order to make the old point to the new, I moved the files on the server and then ran the below script.

UPDATE `wp_posts`
SET post_content = REPLACE(post_content, "uploaded_images", "wp-content/images")
WHERE post_content LIKE "%uploaded_images%"
  1. No comments yet.
(will not be published)