RW_Meta_Box_Taxonomy

Extend RW_Meta_Box class Add field type: 'taxonomy'.

Defined (1)

The class is defined in the following location(s).

/meta-box/meta-box-usage.php  
  1. class RW_Meta_Box_Taxonomy extends RW_Meta_Box { 
  2.  
  3. function add_missed_values() { 
  4. parent::add_missed_values(); 
  5.  
  6. // add 'multiple' option to taxonomy field with checkbox_list type 
  7. foreach ($this->_meta_box['fields'] as $key => $field) { 
  8. if ('taxonomy' == $field['type'] && 'checkbox_list' == $field['options']['type']) { 
  9. $this->_meta_box['fields'][$key]['multiple'] = true; 
  10.  
  11. // show taxonomy list 
  12. function show_field_taxonomy($field, $meta) { 
  13. global $post; 
  14.  
  15. if (!is_array($meta)) $meta = (array) $meta; 
  16.  
  17. $this->show_field_begin($field, $meta); 
  18.  
  19. $options = $field['options']; 
  20. $terms = get_terms($options['taxonomy'], $options['args']); 
  21.  
  22. // checkbox_list 
  23. if ('checkbox_list' == $options['type']) { 
  24. foreach ($terms as $term) { 
  25. echo "<input type='checkbox' name='{$field['id']}[]' value='$term->slug'" . checked(in_array($term->slug, $meta), true, false) . " /> $term->name<br/>"; 
  26. // select 
  27. else { 
  28. echo "<select name='{$field['id']}" . ($field['multiple'] ? "[]' multiple='multiple' style='height:auto'" : "'") . ">"; 
  29.  
  30. foreach ($terms as $term) { 
  31. echo "<option value='$term->slug'" . selected(in_array($term->slug, $meta), true, false) . ">$term->name</option>"; 
  32. echo "</select>"; 
  33.  
  34. $this->show_field_end($field, $meta);