yourprefix_register_taxonomy_metabox

Hook in and add a metabox to add fields to taxonomy terms.

Description

yourprefix_register_taxonomy_metabox(); 

Usage

  1. if ( !function_exists( 'yourprefix_register_taxonomy_metabox' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'cmb2/example-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = yourprefix_register_taxonomy_metabox(); 
  7.  

Defined (1)

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

/example-functions.php  
  1. function yourprefix_register_taxonomy_metabox() { 
  2. $prefix = 'yourprefix_term_'; 
  3.  
  4. /** 
  5. * Metabox to add fields to categories and tags 
  6. */ 
  7. $cmb_term = new_cmb2_box( array( 
  8. 'id' => $prefix . 'edit',  
  9. 'title' => esc_html__( 'Category Metabox', cmb2 ), // Doesn't output for term boxes 
  10. 'object_types' => array( 'term' ), // Tells CMB2 to use term_meta vs post_meta 
  11. 'taxonomies' => array( 'category', 'post_tag' ), // Tells CMB2 which taxonomies should have these fields 
  12. // 'new_term_section' => true, // Will display in the "Add New Category" section 
  13. ) ); 
  14.  
  15. $cmb_term->add_field( array( 
  16. 'name' => esc_html__( 'Extra Info', cmb2 ),  
  17. 'desc' => esc_html__( 'field description (optional)', cmb2 ),  
  18. 'id' => $prefix . 'extra_info',  
  19. 'type' => 'title',  
  20. 'on_front' => false,  
  21. ) ); 
  22.  
  23. $cmb_term->add_field( array( 
  24. 'name' => esc_html__( 'Term Image', cmb2 ),  
  25. 'desc' => esc_html__( 'field description (optional)', cmb2 ),  
  26. 'id' => $prefix . 'avatar',  
  27. 'type' => 'file',  
  28. ) ); 
  29.  
  30. $cmb_term->add_field( array( 
  31. 'name' => esc_html__( 'Arbitrary Term Field', cmb2 ),  
  32. 'desc' => esc_html__( 'field description (optional)', cmb2 ),  
  33. 'id' => $prefix . 'term_text_field',  
  34. 'type' => 'text',  
  35. ) ); 
  36.