Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. add_action( 'cmb2_admin_init', 'yourprefix_register_taxonomy_metabox' );
  2. /**
  3. * Hook in and add a metabox to add fields to taxonomy terms
  4. */
  5. function yourprefix_register_taxonomy_metabox() {
  6. $prefix = 'yourprefix_term_';
  7.  
  8. /**
  9. * Metabox to add fields to categories and tags
  10. */
  11. $cmb_term = new_cmb2_box( array(
  12. 'id' => $prefix . 'edit',
  13. 'title' => esc_html__( 'Category Metabox', 'cmb2' ), // Doesn't output for term boxes
  14. 'object_types' => array( 'term' ), // Tells CMB2 to use term_meta vs post_meta
  15. 'taxonomies' => array( 'category', 'post_tag' ), // Tells CMB2 which taxonomies should have these fields
  16. // 'new_term_section' => true, // Will display in the "Add New Category" section
  17. ) );
  18.  
  19. $cmb_term->add_field( array(
  20. 'name' => esc_html__( 'Extra Info', 'cmb2' ),
  21. 'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
  22. 'id' => $prefix . 'extra_info',
  23. 'type' => 'title',
  24. 'on_front' => false,
  25. ) );
  26.  
  27. $cmb_term->add_field( array(
  28. 'name' => esc_html__( 'Term Image', 'cmb2' ),
  29. 'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
  30. 'id' => $prefix . 'avatar',
  31. 'type' => 'file',
  32. ) );
  33.  
  34. $cmb_term->add_field( array(
  35. 'name' => esc_html__( 'Arbitrary Term Field', 'cmb2' ),
  36. 'desc' => esc_html__( 'field description (optional)', 'cmb2' ),
  37. 'id' => $prefix . 'term_text_field',
  38. 'type' => 'text',
  39. ) );
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement