Manage Or Organize WordPress Media Library Structure In Categories
Posted by in Internet May 14, 2011 6 Comments

Media Library is the images, videos, files, etc you upload and attach/insert into a Post or a Page. If you have so many media uploaded, it’s hard to manage or remember all of them because by default, WordPress doesn’t support Media Categories like Links or Posts.

On my blog, I’ve uploaded over hundreds of screen shots and source codes in attachments in order for my readers download and understand what I say easier. Without Media Categories, I’m always in trouble whenever I want to find a particular media file which was uploaded long time ago.

WordPress Media Library Preview

WordPress Media Library Preview

I researched a lot and found that there is a WordPress Plugin call Media Library Categories will help to organize your Media Library in Categories. This plugin is very easy to install, allow to create category as many as you want, easier for searching your media by filtering a category name. Every time you upload an attachment, you assign a category for it or you can [re]assign the category later via Edit Media function. And all your media can then be sorted per category, this is the function I like most.

Below are some screenshots I captured on my blog in order for you can preview:

1. Display Media Library In Categories Preview

Media Library  Preview

Media Library Preview

As you can see, there is a new link called Media Categories under Add New link in Media box. On Media Library panel on the right, a new column named Categories show which category a media belongs to. And on the top, you can filter the list easier by selecting a category name in the Show All Media Categories drop down list.

2. Manage Your Media Categories

Manage Your Media Categories Preview

Manage Your Media Categories Preview

Currently, I created 2 categories: Screen Shots and Source Code. Basically, I can create as many as I want by clicking on Add Media Category button on the top. After that, just enter a name for the new category and you’re done.

3. Edit Or Add New Media Preview

Add New Or Edit A Media In Category

Add New Or Edit A Media In Category

Every time you add or edit a media, it allows you to select which category the media belongs to.

How to select all media files in a category

This is a extra part for those who are developers because you have to modify a little bit in your PHP template files. Let say you uploaded some images in a category with ID 4 then you want to display all those images in a particular post or a page template. To do that, just use/modify the PHP code below and replace tt.term_id=4 with your desired category id.

echo "<ul>";

$count = 0;
$banners = $wpdb->get_results("
SELECT p.*, a.term_order 
rvsw_posts p inner join 
rvsw_term_relationships a on a.object_id = p.ID inner join 
rvsw_term_taxonomy ttt on ttt.term_taxonomy_id = a.term_taxonomy_id 
inner join rvsw_terms tt on ttt.term_id = tt.term_id 
where ttt.taxonomy='media_category' && tt.term_id=4 
order by a.term_order asc; 


foreach ($banners as $banner) {
	echo sprintf("<li class=\"%s\">",($count == 1)?"active":"");
	echo sprintf("<img src=\"%s\" alt=\"%s\" border=\"0\" class='top_banner'  style=\"display:none;\"/>",$banner->guid,$banner->post_title);
	echo sprintf("<div class=\"ft-title\">%s</div>",$banner->post_title);
	echo sprintf("</li>");
echo "</ul>";

In the PHP script above, $banner->guid will echo the image URL and $banner->post_title will echo the image title.

It’s cool, isn’t it. I uploaded a copy of the Media Library Categories plugin version 1.0.6 for you to download.

Your feedback or question is always welcome, just leave it in the comments.

Hoan Huynh is the founder and head of Reach him at
  • Matt

    Great article. I have many files, with this plugin it will be helpful to compile them all.
    Thanks for sharing!

    • hoanhuynh

      I glad to hear that Matt. Thank you.

  • Domain registration India

    Really awesome post and you are genius. Thanks for sharing this.

  • emmanuel

    it’s 3am in the UK and Ive been looking for this all night!!! love to you!

  • frack

    hi…but where i have to insert that code? in my page.php for examples or in other place?

  • ben Ben

    Do you know of a way to add a bulk edit function for this media library categories?