I want to import into the media library, all the images & videos referenced in my blog posts.
- Can I use
get_attached_media()
to get the images referenced on a page, even if they're not formally attached? - Should I use
media_handle_sideload()
to insert the media into the library?
Background
I've moved hosts, all my blog posts are available and all my images are in /wp-content/uploads/2001/08
etc.
I have around 13,000 images across ~120 subfolders (10 years of blogging ☺).
Here's what I've tried that hasn't worked:
- Import WXR - imported the posts, but wouldn't import the images which were on the same server.
- Media From FTP - didn't work with the huge number of images.
- Add from Server - only works on a per-file basis. I couldn't select a whole folder and all its sub-folders.
- Other plugins seem to suffer from the same issue - they don't deal with nested directories, and they can't cope with thousands of files.
All I want is something to scan my posts, find any <img src="https://example.com/...
, then import that into the media library - leaving the media in the same location. Attachment to the post & regeneration of thumbnails would be a bonus, but not essential.