We are working on a new site for a client and decided that a fresh start would be the way to go. However, we wanted to go ahead and import all of their blog posts too. Unfortunately the WordPress importer doesn’t import images, etc. that are not set as a featured image. We went ahead and uploaded all of the /uploads/[YEAR]/[MONTH] assets into the new site, but we had one problem. None of those items were in the Media Library.
There are other plugins available that allow you to upload all your files into a folder on your server and then import those files into the Media Library. However, if you have existing references to those files within posts and you want the folder structure to remain the same as you need it, you’re out of luck. Well not anymore! We may package this in a plugin, but I’m not sure how common of a problem this is. So for now, here is the code: