Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Including Taxonomy_MetaData_CMB2.php. Update to reflect your file structure
- if ( ! class_exists( 'Taxonomy_MetaData_CMB2' ) ) {
- require_once( 'Taxonomy_MetaData-master/Taxonomy_MetaData_CMB2.php' );
- }
- function taxonomy_metadata_cmb2_init() {
- $metabox_id = 'weekly_cat';
- /**
- * Semi-standard CMB metabox/fields registration
- */
- $cmb = new_cmb2_box( array(
- 'id' => $metabox_id,
- 'object_types' => array(
- 'key' => 'options-page',
- 'value' => array( 'unknown' ),
- ),
- ) );
- $cmb->add_field( array(
- 'name' => __( 'Category Color', 'taxonomy-metadata' ),
- 'id' => 'catt_color',
- 'type' => 'colorpicker',
- ) );
- $cmb->add_field( array(
- 'name' => __( 'Category Serial Number', 'taxonomy-metadata' ),
- 'id' => 'catt_num',
- 'type' => 'text_small',
- ) );
- /**
- * Instantiate our taxonomy meta class
- */
- $cats = new Taxonomy_MetaData_CMB2( 'weekly_cat', $metabox_id, __( 'Extra Field', 'taxonomy-metadata' ), $wlo_overrides );
- }
- add_action( 'cmb2_init', 'taxonomy_metadata_cmb2_init' );
- Available methods for retrieving data:
- ----------------------------------------
- //Get meta for a taxonomy term in to post query and paste this code into query
- $taxonomy = 'weekly_cat';
- $tag_id = $term->term_id;
- $term_color = Taxonomy_MetaData::get( $taxonomy, $tag_id, 'catt_color');
- // Get all meta for a taxonomy term:
- $taxonomy = 'category';
- $term_id = 3;
- Taxonomy_MetaData::get( $taxonomy, $term_id );
- // Get specific term meta data:
- $taxonomy = 'category';
- $term_id = 3;
- $meta_key = 'about_text';
- Taxonomy_MetaData::get( $taxonomy, $term_id, $meta_key );
Advertisement
Add Comment
Please, Sign In to add comment