The Media Library Is Empty but the Files Are on the Server
Media is stored in two places: the files in wp-content/uploads and an attachment row in the database for each. The library lists the database rows. If those are gone and the files remain, the library is empty and the files are still perfectly intact.
The short version
- Confirm the files are actually there before anything else.
- An empty library with intact files is a database problem.
- Check it is not simply a filter or a permissions issue first.
- Rebuilding the links is possible and takes one plugin.
1. Confirm what you have
# files present?
find wp-content/uploads -type f | wc -l
# attachment rows present?
wp post list --post_type=attachment --format=count
Four possible combinations, and they are different problems:
| Files | Rows | Problem |
|---|---|---|
| Many | Many | Not data loss — a filter, permission or JavaScript issue |
| Many | Zero | Database rows lost — rebuildable |
| Zero | Many | Files lost — restore from backup |
| Zero | Zero | Both lost — restore from backup |
2. If both exist, it is not data loss
Check these before assuming anything is gone:
- Switch the library between grid and list view. A JavaScript error breaks grid view and leaves list view working.
- Open the browser console on the media page — an error there is the answer.
- Check whether a filter is set to a date or type with no results.
- Confirm your user role can see other users’ media. Authors see only their own.
- Disable plugins; media-organising plugins can hide items.
3. Rebuilding lost attachment rows
If the files are there and the rows are not, an “add from server” or media-import plugin can scan the uploads directory and recreate an attachment row for each file.
Watch out
Take a database backup before running one. These plugins write many rows at once and the operation is not easily reversed.
What you recover and what you do not:
| Recovered | Not recovered |
|---|---|
| The file itself | Alt text |
| A new attachment ID | Captions and descriptions |
| Thumbnail sizes, after regeneration | The original upload date |
| Visibility in the library | Attachment-to-post links |
The new attachment IDs will differ from the originals, which is why images embedded in posts by ID will not automatically reconnect. Images embedded by URL will still display, because the file path is unchanged.
4. Regenerate the sizes
wp media regenerate --yes
Check your disk and inode headroom first — this creates several files per image.
5. Why the rows disappear
- A partial database restore that missed the attachment rows.
- A migration where only some tables transferred.
- A cleanup plugin that deleted “orphaned” attachments too aggressively.
- A failed bulk delete.
- Table corruption, which
wp db repairmay resolve.
6. If the files are gone too
Then it is a restore. Uploads are usually backed up separately from the database because they are large and rarely change — check whether your backup covers both, which is exactly the thing the quarterly restore drill is for.
Common questions
Will embedded images still display?
If they were embedded with a URL, yes — the file path has not changed. If they were embedded by attachment ID, no.
Can I avoid this?
Back up the database and uploads together, and test a restore quarterly.
Is there a built-in rebuild?
No. WordPress has no command for scanning uploads and recreating attachment rows, which is why a plugin is needed.
Sumit
Writes everything on TechMozz.