Initially the website is built with wordpress. The domain got changed from https://olddomain.com
to https://newdomain.com
and I have to migrate to DB as well.
In the Post content there is image url
like
https://olddomain.com/wp-content/upload/2023/01/imagename.png
https://olddomain.com/wp-content/upload/xxxx/xx/imagename.png
etc.
what i want to achieve is replace https://olddomain.com/wp-content/upload/2023/01/imagename.png
with https://newdomain.com/public/media/images/imagename.png
I tried by using REPLACE
via sql query as following:
Update posts
Set post_description = replace(post_description, 'https://olddomain.com/wp-content/upload/', 'https://newdomain.com/public/media/images/')
The https://olddomain.com/wp-content/upload/xxxx/xx/imagename.png
has become https://newdomain.com/public/media/images/xxx/xx/imagename.png
Now the challenge is replacing /xxxx/xx with ”.
Is it possible with SQL replace or what could be alternate solution.
Thanks!
2
Answers
Here’s an example query that should work:
Try this mysql query: