0

I tried to use the Enable Media Replace ( http://wordpress.org/plugins/enable-media-replace/ ) to replace some images on my site with updated versions. There is an option to update all instances where the file is used on the site, but this only applies to the original image. Wordpress automatically generates several different sizes of each img and renames them "img-size.jpg". These resized image's names are not being updated by the plugin, so anywhere that they are used (like, everywhere) is now a broken image. I looked at the post html and everything looks like:

<a href="mysite.com/wp-content/uploads/2013/12/**newfilename.jpg**"> "img class="size-medium wp-image-1172 alignright" alt="**old file name**" src=mysite.com/wp-content/uploads/2013/12/**oldfilename-300x168.jpg**" width="300" height="168" />"

(ignore the extra quotes, they're just in there so the text would all show up in this post)

Clicking on the broken image will take you to the updated image, but the image is broken in the post. For example, here's a post I replaced images on. http://www.hungrycoqui.com/2013/12/easy-gift-idea/

Is there a mysql command i can use that will turn oldfilename-300x168.jpg into newfilename-300x168.jpg in the img src tag for all instances? Doing it manually would take forever and I know NOTHING about jquery/javascript. It seems like I should be able to use replace() but I'm just not sure how to word it to work for all my images.

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
Tish W.
  • 1
  • 1

1 Answers1

0

Depends if you are looking to replace links in a single post or multiple posts. I haven't seen what's happening with wordpress in years but as far as I remember, the table was called wp_posts.

UPDATE `wp_posts` SET `post_content` = REPLACE(`post_content`, '/newfilename.jpg', '/oldfilename-300x168.jpg');

This would replace the old value with the new one. I would suggest you do that query for every post separately. Add a WHERE statement and post_id = x where x is your post id.

Alexander Ejbekov
  • 5,594
  • 1
  • 26
  • 26