Skip to Content

Mass replace in WordPress posts via MySQL query

I was doing a lot of changes to my old posts, switched to HTTPS, etc. Sometimes it was useful to change some particular text in all my old posts at a time, but there is no such feature in WordPress. But WordPress runs on MySQL and I could use SQL query to update such posts.

Make backup - it’s not required but strongly advised 😃

Now use this query as template to replace in place whatever you need:

e>

You should see something like:

Query OK, 157 rows affected (0.04 sec)
Rows matched: 455  Changed: 157  Warnings: 0

This will remove <!--more-->from all posts (it’s used by WordPress to span article when showed on tag/category pages).

Another example to update all URLs to HTTPS:

UPDATE wp_posts SET post_content = REPLACE(post_content, "http://gagor.pl", "https://gagor.pl");

Be careful with that and make DB backup before you start.