skip to Main Content

I was trying to replace my video link in my wordpress site to another subdomain, I have got a small issue with attached video files.

Under meta_value:

old link: https://example.com/wp-content/uplaods/2022/09/file.mp4

new link: https://newlink.com/my_files/myvids/2022/09/file.mp4

When I run this code:

UPDATE wp_postmeta SET meta_value = replace(meta_value,'old_url.com','new_url.com');

But the problem is that meta_key is same for images and videos: meta_key is: _wp_attached_file

So when I change the link it affects image link as well, however I just want to change the links that contain only mp4 files in meta_value and meta_key with _wp_attached_file . so is there any way to just change the link that contain video files such as .mp4 for example?

Appreciate that.

Regards,

2

Answers


  1. If I understand your question correctly, you should be able to solve it by adding where meta_value like '%mp4'.

    Login or Signup to reply.
  2. You have t6o add a WHERE clause to your Update so that only the values for example with ening mp4 will be updated

    CREATE tABLe wp_postmeta (meta_value varchar(100))
    
    INSERT INTO wp_postmeta VALUEs ('https://example.com/wp-content/uplaods/2022/09/file.mp4')
    ,('https://example.com/wp-content/uplaods/2022/09/file.jpg'),('https://example.com/wp-content/uplaods/2022/09/file.png')
    
    UPDATE wp_postmeta SET meta_value = replace(meta_value,'example.com','examplenew.com')
    WHERE meta_value LIKE '%.mp4'
    
    SELECT * FROM wp_postmeta 
    
    meta_value
    [video  src="https://examplenew.com/wp-content/uplaods/2022/09/file.mp4" /]
    https://example.com/wp-content/uplaods/2022/09/file.jpg
    https://example.com/wp-content/uplaods/2022/09/file.png 
    

    db<>fiddle here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search