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? 🙂

7 Comments

  1. Thank you for this post. It was a problem I used to get every now and then and it frustrated me to no end.

  2. Thanks for this explanation. I’m having the same problem and was looking for a solution. I’m going to try it and see if it works for me too.

    Thanks,

    Terry

  3. Thank you, that is exactly, what i needed!! You made my day 😉

    Regards from germany!

  4. Thankyou so much for this, was exactly what i was looking for!! i am bookmarking your website for future use 🙂

  5. Awesome info. Thanks for sharing.

  6. Great info! I recently came across your blog and have been reading along. Nice post.

  7. Great info! I can certainly see a huge future headache has been saved. Good point on commenting everything out and then adding back in one by one too.

Add a Comment

If you have used this form and would like a copy of the information held about you on this website, or would like the information deleted, please email info@zigpress.com.