RUSSEL86

Taxonomy Metadata Example

Feb 7th, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. <?php
  2. // Including Taxonomy_MetaData_CMB2.php. Update to reflect your file structure
  3. if ( ! class_exists( 'Taxonomy_MetaData_CMB2' ) ) {
  4. require_once( 'Taxonomy_MetaData-master/Taxonomy_MetaData_CMB2.php' );
  5. }
  6.  
  7. function taxonomy_metadata_cmb2_init() {
  8. $metabox_id = 'weekly_cat';
  9. /**
  10. * Semi-standard CMB metabox/fields registration
  11. */
  12. $cmb = new_cmb2_box( array(
  13. 'id' => $metabox_id,
  14. 'object_types' => array(
  15. 'key' => 'options-page',
  16. 'value' => array( 'unknown' ),
  17. ),
  18. ) );
  19. $cmb->add_field( array(
  20. 'name' => __( 'Category Color', 'taxonomy-metadata' ),
  21. 'id' => 'catt_color',
  22. 'type' => 'colorpicker',
  23. ) );
  24. $cmb->add_field( array(
  25. 'name' => __( 'Category Serial Number', 'taxonomy-metadata' ),
  26. 'id' => 'catt_num',
  27. 'type' => 'text_small',
  28. ) );
  29.  
  30. /**
  31. * Instantiate our taxonomy meta class
  32. */
  33. $cats = new Taxonomy_MetaData_CMB2( 'weekly_cat', $metabox_id, __( 'Extra Field', 'taxonomy-metadata' ), $wlo_overrides );
  34. }
  35. add_action( 'cmb2_init', 'taxonomy_metadata_cmb2_init' );
  36.  
  37.  
  38.  
  39. Available methods for retrieving data:
  40. ----------------------------------------
  41. //Get meta for a taxonomy term in to post query and paste this code into query
  42. $taxonomy = 'weekly_cat';
  43. $tag_id = $term->term_id;
  44. $term_color = Taxonomy_MetaData::get( $taxonomy, $tag_id, 'catt_color');
  45.  
  46. // Get all meta for a taxonomy term:
  47. $taxonomy = 'category';
  48. $term_id = 3;
  49. Taxonomy_MetaData::get( $taxonomy, $term_id );
  50.  
  51. // Get specific term meta data:
  52. $taxonomy = 'category';
  53. $term_id = 3;
  54. $meta_key = 'about_text';
  55. Taxonomy_MetaData::get( $taxonomy, $term_id, $meta_key );
Advertisement
Add Comment
Please, Sign In to add comment