HomeHow ToWordpress: Bulk URL change from SQL

WordPress: Bulk URL change from SQL

Let's "talk" about WordPress. After merging the secnews.gr database into the secnews database, all image links pointed to the secnews.gr directories. For example:

wordpress-code

https://cdnglobal.secnews.gr/wp-content/uploads/2016/10/19111852/Mechanic.jpg

So even though the posts were on secnews, the images continued to come from iguru. So after we moved all the files from /uploads of iguru to the eponymous dir of secnews, we had to massively change the URLs so that they would get the images from:

https://www.secnews.gr/wp-content/uploads/

Let's see how it's easy (before trying it, make a backup of your database):

Below are the SQL commands we used to change the URLs across the database.

UPDATE wp_options SET option_value = replace(option_value, 'https://www.secnews.gr/wp-content/uploads', 'https://www.secnews.gr/wp-content/uploads') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'https://www.secnews.gr/wp-content/uploads','https://www.secnews.gr/wp-content/uploads');
UPDATE wp_posts SET post_content = replace(post_content, 'https://www.secnews.gr/wp-content/uploads', 'https://www.secnews.gr/wp-content/uploads');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'https://www.secnews.gr/wp-content/uploads','https://www.secnews.gr/wp-content/uploads');
📧
Subscribe to the SecNews Newsletter

The most important Security & Technology news in your Inbox.

SecNews
SecNewshttps://www.secnews.gr
In a world without fences and walls, who needs Gates and Windows

SEARCH

FOLLOW US

📧
Newsletter SecNews
The most important Security & Technology news in your inbox.

LIVE NEWS