How do I restore attachment from files in wp-upload

Yes, you can do this. First set up a loop that loops through all the images in the upload directory. Then construct an array with the required data needed to create a new post of the type attachment: $dir = new DirectoryIterator(wp_upload_dir()[0]); foreach ($dir as $maybeFile) { if ($maybeFile->isFile()) { $filename = $maybeFile->getPathname(); $wp_filetype = … Read more