Home Media Library Reset Featured Images at Random on Restore of 5-min Old wp_postmeta Backup, WP 4.9.1
Reply: 0

Media Library Reset Featured Images at Random on Restore of 5-min Old wp_postmeta Backup, WP 4.9.1

user3834 Published in April 22, 2018, 12:48 am

The Situation: Established, stable site. Changed themes. Both new and old are from same developer and use the same code for most things, including post templates created by the themes. The template for each post is managed by a custom field/meta box in both themes. field post_template gets a value, in my case, the old theme used temp2 and the new theme uses temp3. New theme activated fine, no issues. But temp2 in the new theme is not a good template, so that needs to change. Only some posts had the template explicitly set. There's also a global variable that responds to options in the theme's settings panel. Still, of 4,600 total posts, 1,423 needed to be changed.

The Problem: WP search and replace plugins weren't specific enough. If a field had temp2 in it, even if it wasn't the full value, but part of it, it wanted to replace it. So I couldn't use that. Next option was to export a current SQL backup of the wp_postmeta table and manually do a search and replace in Sublime Text 3. Took 5 minutes and was done, no issues, no other values altered, and a complete (60MB) file was exported and imported back into the database (beginning and end of file markers present). Suddenly, 3/4 of the posts were missing featured images. Not only were the media files detached from the posts, but they no longer read right in the media library either, showing a grey square instead of the image. There is no rhyme or reason to which posts were affected; it's random, not even matching with the posts that were explicitly affected by the template change. I did an exact search and replace; replaced 'temp2' with 'temp3' to ensure it was only grabbing values with nothing but those 5 characters, including single quotes. Quotes were used, not backticks, I checked. All media used within the scope of the_content() was unaffected (images, video, audio, embeds).

The Set Up: All posts have featured image going back for six years, spottier before that, but the last few years is all that matters. Regularly updated site running WP 4.9.1 without issues before I did the edit. That's with either theme. The uploads directory remained entirely unchanged throughout this process (last alteration was 20 minutes before the table export). Themes both use thumbnail features and all thumbs were generated to match thumb support. Running PHP 7.1 on a Debian machine with Apache 2 and Nginx. MySQL is MariaDB 10. Again, all was working perfectly (at 35,000 hits a day); zero issues. Site is 8 years old, but I did a fresh install of WP in Feb 2017 and manually imported all content and media to clean up years of cluttering metadata.

Have Tried: Tried the Add From Server plugin and that brings the files back to the media library, but does not re-attach them to the posts. Honestly, I can't think of anything else to try. I've searched online but every issue I find is about other circumstances, not working with already in-place and error-free data. Can find nothing about a current backup causing these kinds of issues after 5 minutes (literally? maybe 6 minutes) and without any changes (no authors were working at the time, just visitors visiting). I even tried the VaultPress backup and it erred out completely. I can't go back since the backup is already what I did to cause this issue. There is no value in the entire database that is exactly 'temp2' that corresponds to anything related to the problems I'm experiencing.

Open to any ideas at this point. We use thumbs on every post to achieve the desired aesthetic of the site. Looks bad right now with so many thumbs missing.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.302326 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO