cmb2-taxonomy icon indicating copy to clipboard operation
cmb2-taxonomy copied to clipboard

Image filed for taxonomy not shwing on front end

Open TheNewGuy16 opened this issue 8 years ago • 2 comments

Hey having trouble getting the image to show up on the front end using cmb2 taxonomy. I have used regular cmb2 for other stuff and it works great. I have a custom taxonomy for a custom post type and i need to get the image of the taxonomy and display it as a banner for each of my post types. but its not coming up. Its saving to the DB but not getting displayed on the front end when i use

`add_filter('cmb2-taxonomy_meta_boxes', 'cmb2_taxonomy_metaboxes');

/**

  • Define the metabox and field configurations.

  • @param array $meta_boxes

  • @return array */ function cmb2_taxonomy_metaboxes( array $meta_boxes ) {

    // Start with an underscore to hide fields from custom fields list $prefix = 'cmb2_taxonomy';

    /**

    • Sample metabox to demonstrate each field type included */ $meta_boxes['taxonomy_metabox'] = array( 'id' => 'taxonomy_metabox', 'title' => __( 'Taxonomy Metabox', 'cmb2' ), 'object_types' => array( 'collection_category', ), // Taxonomy 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left // 'cmb_styles' => false, // false to disable the CMB stylesheet 'fields' => array( array( 'name' => __( 'Collection Banner', 'cmb2' ), 'desc' => __( 'Upload an image or enter a URL.', 'cmb2' ), 'id' => $prefix . 'collection_banner', 'type' => 'file', ), ), );

    return $meta_boxes; }` that saves the meta box and it is saving to the db then to display it i have

$bannerImg = get_term_meta(get_the_ID(), '_cmb2_taxonomy_collection_banner',true);?> <div class="col-xs-12 banner-image" style="background-image: url('<?php echo $bannerImg?>');"></div> but don't see it on the front end.

I see you refer to the basic usage for cmb2 but none of that is working. So can you give me an example of how to add an image field and display that image on the front end using cmb2 taxonomy?

TheNewGuy16 avatar Feb 13 '17 16:02 TheNewGuy16

Hello, Us term_id instead of get_the_ID() e.g, <?php $terms = get_terms( array( 'taxonomy' => 'collection_category', 'hide_empty' => false, ) ); foreach($terms as $term) { echo (get_term_meta( $term->term_id, '_cmb2_taxonomy_collection_banner', true )); }?>

irfandeveloper avatar Mar 21 '17 10:03 irfandeveloper

Hello, Us term_id instead of get_the_ID() e.g, <?php $terms = get_terms( array( 'taxonomy' => 'collection_category', 'hide_empty' => false, ) ); foreach($terms as $term) { echo (get_term_meta( $term->term_id, '_cmb2_taxonomy_collection_banner', true )); }?>

@irfandeveloper Thank you. The exact code he's been looking for for a long time. But it lists all metabox values. I just want the corresponding value to be taken. So let it be taken separately. How can I do it?

mehmetsarr avatar Oct 09 '20 05:10 mehmetsarr