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' ); ?>
  • the id is '_textinfo_bookimg' – inarilo Dec 29 '17 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 Dec 29 '17 at 22:55
  • you have to echo the result of wp_get_attachment_image, it returns an html string – inarilo Dec 30 '17 at 4:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.