2

I have a problem get the image with cmb2, I have tried in many ways without successm according to the documentation, this is fine, what can I be doing wrong?

add_action( 'cmb2_admin_init', 'cmb2_sample_metaboxes2' );
function cmb2_sample_metaboxes2() {
    // Start with an underscore to hide fields from custom fields list
    $prefix = '_textinfo_';
    $cmb = new_cmb2_box( array(
        'id'            => 'book_metabox',
        'title'         => __('information', 'cmb2' ),
        'object_types'  => array( 'book', 'page'  ), // Post type
        'context'       => 'normal',
        'priority'      => 'high',
        'show_names'    => true, // Show field names on the left
    ) );
  $cmb->add_field( array(
    'name' => 'Book Name',
    'id'   => $prefix . 'book',
    'type'            => 'textarea',
    'sanitization_cb' => false,
) );
      $cmb->add_field( array(
    'name' => 'Book Image',
    'id'   => $prefix . 'bookimg',
    'type'            => 'file',

) );    }

does not work

<?php wp_get_attachment_image( get_post_meta( get_the_ID(), '_textinfo_bookimg_id', 1 ), 'thumbnail' ); ?>
3
  • the id is '_textinfo_bookimg'
    – inarilo
    Commented Dec 29, 2017 at 20:24
  • I have tried it that way and according to documentation it is necessary to id It will store it in $ id. '_id',
    – Max
    Commented Dec 29, 2017 at 22:55
  • you have to echo the result of wp_get_attachment_image, it returns an html string
    – inarilo
    Commented Dec 30, 2017 at 4:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.