Search code examples
wordpresswordpress-themingtaxonomycustom-taxonomy

Adding custom taxonomy to media gallery in wordpress admin


I have added a custom taxonomy to Media, which is showing up as a text field in the Media admin section. I would like this to be the typical checkbox format as it exists in the custom post type admin page. Is there a way to override this in the functions to make this custom taxonomy show in checkboxes, so the user could easily choose which image belongs to a specific taxonomy entry?

Here is the code I used to bring the taxonomy into the Media Gallery:

  register_taxonomy('Categories',array('project', 'slides', 'attachment'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'categories' ),
  ));

In the first line, by adding 'attachment' to the array, it added the Project Categories field in the Media Gallery. Now I just need to make this a list of checkboxes containing the current taxonomy entries. Any thoughts on how to achieve this?

I found this article, but having never used filters, it was a bit perplexing as to how to make this work for me:

https://wordpress.stackexchange.com/questions/29858/adding-category-tag-taxonomy-support-to-images-media


Solution

  • You are most of the way there. To render a taxonomy category as a special HTML display, like a list of checkboxes, the best method is to use the built-in WordPress Walker class. It is made exactly for this sort of thing.

    http://codex.wordpress.org/Function_Reference/Walker_Class

    I use this very method to create a new "SLP_Tagalong" walker class that renders a list of my taxonomy categories as a list of checkboxes (I only show text names but it could easily show the marker images) whenever anyone edits a store location.

    I have the modified Walker Class I can share if you would like to see it. I'd post here but it is 150 lines. Send me a PM and I'll shoot it back that way.