Category Metabox Echo Not Displaying
-
I have added the following code:
add_action( 'cmb2_admin_init', 'series_taxonomy_metabox' ); /** * Hook in and add a metabox to add fields to taxonomy terms */ function series_taxonomy_metabox() { $prefix = 'dc_tax'; /** * Metabox to add fields to categories and tags */ $cmb_term = new_cmb2_box( array( 'id' => $prefix . 'series_tax', 'title' => esc_html__( 'Series Metabox', 'cmb2' ), // Doesn't output for term boxes 'object_types' => array( 'term' ), // Tells CMB2 to use term_meta vs post_meta 'taxonomies' => array( 'series_hub' ), // Tells CMB2 which taxonomies should have these fields // 'new_term_section' => true, // Will display in the "Add New Category" section ) ); $cmb_term->add_field( array( 'name' => esc_html__( 'Term Image', 'cmb2' ), 'desc' => esc_html__( 'field description (optional)', 'cmb2' ), 'id' => $prefix . 'avatar', 'type' => 'file', ) ); }
This creates a file field and saves to database.
My problem I am having is I can’t display my data on my category template page.
I am using the following code as a test just to display the url. Then I’m going to add all if’s that i need and img tag.
<?php $avatar = get_term_meta( get_the_ID(), 'dc_tax_avatar', true ); if(empty($avatar)){ echo 'empty'; } else { echo '<span style="color:#fff;">'. $avatar .'</span>'; } ?>
Any ideas on why its not working?
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Category Metabox Echo Not Displaying’ is closed to new replies.