Support » Plugin: CMB2 » cmb2 field type : file is not displaying image on front end?

  • Resolved kuasaslash


    By using cmb2 field type => file, In backend image file was uploaded but in front end it’s not displaying, I checked with inspect element and in that found image src unknow, Please help

    Shortcode section

    `// Client Section Shortcode


    function home_client_section_shortcode($attr,$content){

    $client = extract(shortcode_atts( array(
    ‘title’ => ‘Oue Clients’,
    ‘subtitle’ => ‘Some of the best.’

    ), $attr) );

    ob_start(); ?>

    <div class=”container”>
    <div class=”title center”>
    <h4 class=”upper”><?php echo $subtitle; ?></h4>
    <h3><?php echo $title; ?><span class=”red-dot”></span></h3>
    <div class=”section-content”>
    <div class=”boxes clients”>


    $client = new WP_Query( array(
    ‘post_type’ => ‘agro-client’,
    ‘posts_per_page’ => 10


    $logo = wp_get_attachment_image( get_post_meta( get_the_id(),’_client-logo’, true),’medium’ );

    while($client->have_posts()): $client->the_post();


    <div class=”col-sm-4 col-xs-6 border-right border-bottom”>

    <img src=”<?php echo $logo; ?>” alt=”” data-animated=”true” class=”client-image”>


    <?php endwhile; ?>


    <?php return ob_get_clean();

    • This topic was modified 1 year, 2 months ago by kuasaslash.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter kuasaslash


    // Home Client Section meta box

    $client= new_cmb2_box( array(
    ‘title’ => ‘ Client Logo Upload Fields’,
    ‘id’ => ‘client_fields’,
    ‘object_types’ => array(‘agro-client’)


    $client-> add_field( array(
    ‘name’ => ‘Upload Client Logo’,
    ‘id’ => ‘_client-logo’,
    ‘type’ => ‘file’,
    ‘options’ => array(
    ‘url’ => false, // Hide the text input for the url
    ‘text’ => array(
    ‘add_upload_file_text’ => ‘Add or Upload Logo’ // Change upload button text. Default: “Add or Upload File”


    Thread Starter kuasaslash


    It’s not a spam

    Plugin Author Michael Beckwith


    The BenchPresser

    Hi @kuasaslash

    Looks like you’re trying to fetch the image with…the image.

    The meta value you’re passing in to wp_get_attachment_image() fetched from the meta tag is the image URL itself, not an attachment ID.

    Check out quick and note that it says:

    This field type will also store the attachment ID (useful for getting different image sizes). It will store it in $id . ‘_id’, so if your field id is wiki_test_image the ID is stored in wiki_test_image_id”

    So if you’re wanting the ID of the associated attachment, fetch _client-logo_id with your get_post_meta call and it should handle the rest with the code you have now.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘cmb2 field type : file is not displaying image on front end?’ is closed to new replies.