(All plugins disabled) I have some strange issues with the media library. It's an old site that I have been managing for the last 2 years. The site has dated media folders on disk going back to /2010/01/.

The dropdown in media library to filter items by date only goes back to June 2013. If I select that date it shows two images. However if I look on disk there are about 70 images (not including other sizes).

I ran the following query in PMA as a routine:

    SELECT meta_value AS filename
    FROM wp_posts p
    JOIN wp_postmeta pm ON p.id = pm.post_id
    WHERE p.post_type = 'attachment' AND pm.meta_key = '_wp_attached_file'
    INTO OUTFILE '/tmp/filenames.log' 

Which gave me file paths from 2010 but, for example, in 2010/01 it only returned one image path when there are actually 7 images on disk in that folder.

Is there something, code or plugin, that will recurse through folders on disk and check if a media item doesn't appear in the media library and add it?

1 Answer 1


What you need is a way to scan your uploads directory and register any unregistered files. There are plugins that can help with this. One such plugin is "Add From Server". This allows you to import media and files into the WordPress uploads manager from the server's file system. Using this plugin, you can import those files from your disk into the WordPress database, which should make them appear in the Media Library.

  • I am aware of that plugin, but I wasn't sure from their docs if it skips files that already exist in the media library. After scanning their code it looks like it will skip so will give it a test. Commented Dec 12, 2023 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.