Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Alex Flores7,864 Points
Issue with WordPress images and the database
I uploaded a bunch of images via FTP transfer and for some reason they didn't show up in the WordPress media library. So I uploaded all 3k of them via the media library - 40 at a time... Then I added a bunch products using WP All Import and the image was supposed to attach to the product, but the images were corrupt. So I tried finding the corrupt images in the media library so I could delete them, but I couldn't find them.
So, my question is this, how does the WordPress database work in relation to the server? I want to start anew by just deleting all of the images and doing uploading them again. But it seems like if I delete them in the media library, they won't necessarily all be gone. Do I have to also delete them from the database?
I just want to start from scratch.
Sean Roberts4,856 Points
If you upload a file through the WP Admin the image file is uploaded to a dynamically generated folder on your server in the wp-uploads directory. The image data (path, id, file type ect) is passed to the WordPress database as an object. If you delete an image from the WP Admin it will erase the image file from the server and the image data from the database.
If you simply upload the images to your server WordPress will not add the images to the media library because the image data never gets passed to the database. As far as WP is concerned the images do not exist. There is a plugin workaround (https://wordpress.org/plugins/media-from-ftp/) but its probably not the best option.
If the goal is to bulk import products I recommend uploading the images to the server via FTP in the pubic_html directory the add the product image urls to your import spreadsheet. As long as the image paths are correct and WP All Import is configured correctly the images will be uploaded to WordPress and attached to the corresponding post (product).
Alex Flores7,864 Points
Sean, you were right. That's exactly what I did and it worked out great. Also, for some reason, the option to mark your answer as best isn't available to me. This has happened to me before. I think this is a Treehouse bug.