Items in the media library are represented by rows in wp_posts
. They have post_type = 'attachment'
. Did you DELETE some of those rows?
Edit: For an item to appear in WordPress's media library, it must both appear someplace in the /uploads/YYYY/MM/
folder and in an 'attachment'
row in the wp_posts
table. Each media library item has its own row in that table. It seems unlikely that changing post_type
values in that table will restore your media library. Unless they're still there and you somehow changed their post_type
values when you were messing around. Unlikely.
Do you have a backup of your database? If so, restore it. That is your best bet.
At any rate, make a backup before you start trying to repair this problem. Then make regular backups. It's not hard, and it will save you untold grief in the future.
Do you have dozens of missing items? If so, download them from your WordPress file system with FTP, then re-upload them with the WordPress media library functionality, to re-create them.
Edit Don't delete them from your uploads/YYYY/MM
folders; just re-upload them. They'll end up in two places in those folders, with the newer of the two corresponding to the newly created 'attachment'
row in wp_posts
. Older posts should still render correctly, using the older image files in the folders.
If having some images show up twice in uploads
is a problem, sorry. Please see my question above about backups. Don't experiment with a running WordPress instance by messing with the database. In the same way, don't experiment with your car by trying different substances in the fuel tank. If you put vodka or vegetable oil in there, the car won't run any more, and the reasons will be messy.
Or, try using the AddFromServer plugin to restore your missing items. https://wordpress.org/plugins/add-from-server/
Do you have hundreds, or more, of missing items? If so, you could be in a genuinely unpleasant situation.