SQL is a great tool if you want to make changes to all your posts at once. Especially if you want to replace some old string with new ones it will be really helpful. In this post, I am going to show you how you can replace old links in your posts using SQL.


1. Backup Your Database

Even though SQL is a really powerful tool, it is also a really dangerous one. So, before proceeding to run any wild queries on your WordPress database, I recommend you to backup your database first. If you have CPanel this is a really simple thing to do. If you don’t I recommend using some plugin to download your database backup.


2. SQL Query to Replace Old Links on Your WordPress Database

You can use phpMyAdmin or an SQL query plugin to run following query on your WordPress database:

UPDATE 'wp_posts' SET 'post_content' = REPLACE( 'post_content', "http://old-link.example.com", "https://new-link.example.com" ) WHERE 'post_type'="post";

This query will replace all occurrences of the old link on your database, with the new one.


I hope you liked this trick. Follow our social accounts for the latest updates and more tips like this.

(via metinsaylan.com)