0

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

Community
  • 1
  • 1
Carey Estes
  • 1,534
  • 2
  • 31
  • 59

2 Answers2

2

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.

Lance Cleveland
  • 3,098
  • 1
  • 33
  • 36
  • Thanks! I would like to check out your Walker class. I am stumped as to how to send you a message though. Could you send it to my email address, carey@careyestes.com? – Carey Estes Feb 20 '13 at 19:32
  • Just to confirm, the walker_class would provide customized html output in the wp admin section, correct? Every example I am looking at is referencing the wp_nav_menu on the frontside. – Carey Estes Feb 20 '13 at 20:01
  • I have an even easier solution. wp_terms_checklist() from WordPress Codex. Google that. ob_start(), wp_terms_checklist(); $HTMLOutput = ob_get_clean(); – Lance Cleveland Mar 18 '13 at 05:53
0

I am sure the walker class would have worked successfully, but looking at the codex reminded me of string theory and existentialism. The upside is with WP 3.5.1, when you associate a taxonomy to 'attachment' set to Hierarchal, the checkbox appears in the Media Library by default.

YAY!!

This may not answer the question posed thoroughly though so I will leave it open for anyone who wants to stab at this.

Carey Estes
  • 1,534
  • 2
  • 31
  • 59