Media Library images missing in modal uploader
This is an interesting little WordPress problem, and I don’t think I’ve seen a solution posted elsewhere.
On a couple of projects recently, I found that, while creating a custom theme and custom plugins, the “Media Library” tab of the WordPress modal media uploader suddenly stopped showing the list of images. It still showed an image count but the images themselves were not displayed.
I deactivated all plugins and found that the problem disappeared. I then reactivated them one by one and found that it was my custom plugin that caused the problem. I heaved a sigh, commented out the content of all my plugin’s method functions, and then uncommented them line by line until I found the code that was responsible. I found that the culprit code was using the register_taxonomy() function to create a custom taxonomy called “type”. As soon as I renamed the custom taxonomy to something other than “type”, the problem disappeared.
However, I wasn’t convinced that this made sense, and I realised another thing: my call to register_taxonomy() was happening in my plugin’s class constructor, rather than inside an action hook. I renamed the custom taxonomy back to “type” (just to prove the point), put the call into the “init” action, and everything worked fine. However, I’ve now decided to avoid using the name “type” for custom content types and taxonomies, just in case it breaks something else that I haven’t noticed yet.
And if you’re thinking “but these solutions have nothing to do with the media library or modal uploader”, then you’re not alone! I’m chalking it up as one of WordPress’s little foibles. It has quite a few after all.
So, if you have this problem while developing a WordPress site, check two things:
1. If you are creating custom content types and taxonomies, make sure they are created within the “init” action.
2. If you are creating a custom taxonomy, I’d advise not calling it “type” to be on the safe side.
Please note that if you actually read the WordPress Codex documentation for the register_taxonomy() function in its entirety, you’ll find advice about both of these issues (using the function in an action, and avoiding reserved words). However, since when do most developers read more documentation than they think they can get away with? :-)