Quite often, especially when working with WordPress sites, I need to update content with a new web address. This happens when a site has been on a preview domain whilst being populated, and WordPress likes to put absolute paths in place for image uploads and the like.
Without having to go through EVERY post and altering the domain, if you have access to the SQL database – through something like phpMyAdmin, or hard-core command line – you can update the data by using inbuilt REPLACE funtion.
Simply execute the following code (if you’re updating WordPress posts).
1 |
UPDATE wp_posts SET post_content = REPLACE(post_content, 'preview.domain.com', 'new.domain.com'); |
Or check out the below for a break down of how it works:
1 2 |
UPDATE tablename SET column_to_update = REPLACE(column_to_update, 'string_to_match', 'new_string'); |
Image Credit: therefromhere
Comment or tweet @douglasradburn