WordPress.org

Ready to get started?Download WordPress

Plugin Directory

Media Categories

Easily assign categories to media with a clean, simple, and searchable category meta box. Then use the gallery shortcode to display category galleries

Shortcode Usage

Normal Shortcode Usage

This plugin takes advantage of the existing [gallery] shortcode for showing images by adding the 'category' parameter. The value passed to the 'category' parameter can be either the category slug, or the term_id.

[gallery category="my-category-slug"]
OR
[gallery category="12"]

Its important to note that when passing the 'category' parameter, the [gallery] shortcode will by default ignore the current post and simply try to include all images from the category. The syntax above will retrieve any images that are assigned to 'my-category-slug' a.k.a term id #12, regardless of whether or not those images are attached to the current post.

To query within a post (even the current post), you'll need to explicitly add the post id as such...

[gallery category="my-category-slug" id="43"]

This shortcode will retrieve any images attached to post #43 that are categorized as 'my-slug-category'.

Aside from this behavior, the [gallery] shortcode should behave exactly as it does by default with the built-in shortcode. The id parameter will behave as normal when the category parameter is not invoked. For more information on using the built-in gallery shortcode checkout the codex page.

Other Taxonomy Shortcode Usage

If a developer implementing this plugin has made use of the mc_taxonomy filter to modify which taxonomy this plugin uses for attachments, then the name of that particular taxonomy will need to be used in place of category as the shortcode parameter. For example, if you applied 'Post Tags' to your images then users should use the post_tag parameter in the Gallery Shortcode.

[gallery post_tag="my-tag-slug"]
OR
[gallery post_tag="12"]

[Warning: nerdy developer stuff ahead]

Multiple Taxonomy Metaboxes *NEW!*

Since 1.4 this plugin allows developers to create metaboxes for any number of taxonomies. While previous the previous version allowed developers to change the taxonomy being used, it still only allowed a single taxonomy metabox to be generated. With 1.4, that has changed.

All a developer needs to do, is create a new instance of the Media_Categories class and pass their desired taxonomy as an argument.

$my_custom_media_metabox = new Media_Categories('my_custom_taxonomy');

Thats it!, nothing else to it, the plugin will take care of the rest. You can create as many instances as you like - just make sure to be careful when doing this in conjunction with the mc_taxonomy filter - always check the current taxonomy.

Obviously this works with any taxonomy, including built-in taxonomies such as 'post_tag', 'link_categories', and yes, even 'nav_menu'. I'll leave it to you developers out uses for that.

Taxonomy Filter Usage: 'mc_taxonomy'

Note: Since 1.4, this plugin allows developers to generate any number of metaboxes, for any number of different taxonomies. Because of this, it is important that when filtering the taxonomy, developers conditionally check the current taxonomy before returning a different - otherwise the filter would override all instances of the plugin's metaboxes with the same taxonomy. The examples below have been changes accordingly

Since version 1.3, the Media Categories plugin includes a filter allowing developers to modify the taxonomy being used. Changing the taxonomy will automatically change all the labels used around the metabox, and change the way the Gallery Shortcode works so that it accommodates whatever taxonomy has been chosen.

The tag for this filter is 'mc_taxonomy', and usage could not be simpler.

add_filter('mc_taxonomy', 'mc_filter_taxonomy');

function mc_filter_taxonomy($taxonomy){

    if($taxonomy == 'category'){
        $taxonomy = 'post_tag';
    }

    return $taxonomy
}

The above code will swap out all references to 'category' with appropriate (properly pluralized) references to the 'post_tag' taxonomy.

It will also change the way the Gallery Shortcode works to use your chosen taxonomy.

Important (potential gotchas)

  • The category parameter for the Gallery Shortcode will be changed by using this filter, so that instead of category is will by your_taxonomy. In the case above with tags, you would write a shortcode as such. [gallery post_tag="my-tag"] OR [gallery post_tag="43"].
  • If using a Custom Taxonomy with this plugin, be sure to assign values to the labels for proper pluralization and context

Checkout this great plugin for Searchable Categories by Jason Corradino, whose javascript I use in this plugin. I believe this very simple functionality should be a part of the standard categories metabox in core. While I do not employ the plugin directly, the javascript used for filtering/searching is in fact derived with consent, and a few modifications from that plugin. To enable this feature on all your category metaboxes, install the Searchable Categories plugin.

Requires: 3.3 or higher
Compatible up to: 3.5.2
Last Updated: 2012-12-18
Downloads: 23,389

Ratings

3 stars
3.7 out of 5 stars

Support

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

100,1,1 0,1,0
100,1,1 100,1,1 100,1,1
100,1,1
100,1,1 100,1,1
100,1,1 50,2,1 67,3,2 100,1,1 100,1,1
0,1,0
100,1,1
80,5,4
100,2,2
50,2,1
50,2,1
100,1,1