Taxonomies for WordPress Media Library

I know this has been a long debated issue with WP, but I was hoping that since the 3.5 upgrade, there has been some progress in categorizing images in the Media Library.

Really, what I am hoping to accomplish is creating a set of categories for the images in the Media Library, and then assigning the current images, or future images, to those categories.

Read More

Then, later down the road I could call them in a page template based on their category. Any ideas WPA?

Many thanks.

Related posts

Leave a Reply

2 comments

  1. See the question / answer on this link.
    The answer have 2 different solutions, easy with default categories and taxonomies and also a solution with custom taxonomies only for media.

  2. A starting point, adding the default category to the attachment post type:

    add_action( 'init', 'wpse_77550_media_categories' );
    
    function wpse_77550_media_categories()
    {   
        register_taxonomy_for_object_type( 'category', 'attachment' );
    }
    

    Or adding a custom taxonomy to the attachment post type (not sure why the taxonomy doesn’t show up in the Media menu –show_ui=>true-, although the meta box shows up when editing an attachment):

    add_action( 'admin_init', 'wpse_77550_media_taxonomy' );
    
    function wpse_77550_media_taxonomy()
    {   
        $labels = array(
            'name' => _x( 'Genres', 'taxonomy general name' ),
            'singular_name' => _x( 'Genre', 'taxonomy singular name' ),
            'search_items' =>  __( 'Search Genres' ),
            'all_items' => __( 'All Genres' ),
            'parent_item' => __( 'Parent Genre' ),
            'parent_item_colon' => __( 'Parent Genre:' ),
            'edit_item' => __( 'Edit Genre' ), 
            'update_item' => __( 'Update Genre' ),
            'add_new_item' => __( 'Add New Genre' ),
            'new_item_name' => __( 'New Genre Name' ),
            'menu_name' => __( 'Genre' ),
          );    
    
          register_taxonomy('genre','attachment', array(
            'hierarchical' => true,
            'labels' => $labels,
            'show_ui' => true,
            'show_admin_column' => true,
            'query_var' => true,
            'rewrite' => array( 'slug' => 'genre' ),
          ));
    }
    

    Reference:
    How To: Add Taxonomies to Your Custom Post Types in WordPress