Skip to content
Home » WordPress » How to Change URL in All Posts

How to Change URL in All Posts

Sometimes, we want to change linking URL in posts. But hundreds or even thousands of post? How can we do it in a second?

In this case, we directly update mysql database to change linking URL for all wordpress posts. For example, we changed linking URL.

From:

http://example.com

To:

https://www.example.com

Before doing the following steps, you should make sure that you have backed up the database in case of any accident.

Count Rows for Update

To ensure we update exactly what we want, we count the rows that match our requirements.

mysql> select count(*) cnt from wordpress_example_posts where post_content like '%http://example.com%' and post_type = 'post' and post_status = 'publish';
+-----+
| cnt |
+-----+
| 728 |
+-----+
1 row in set (0.02 sec)

Update Database

Now we update posts which contains the URL by REPLACE function.

mysql> update wordpress_example_posts set post_content = replace(post_content,'http://example.com','https://www.example.com') where post_content like '%http://example.com%' and post_type = 'post' and post_status = 'publish';
Query OK, 728 rows affected (0.44 sec)
Rows matched: 728  Changed: 728  Warnings: 0

We made it.

Leave a Reply

Your email address will not be published. Required fields are marked *