Skip to content

Instantly share code, notes, and snippets.

@mustardBees
Created June 3, 2013 15:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustardBees/5699128 to your computer and use it in GitHub Desktop.
Save mustardBees/5699128 to your computer and use it in GitHub Desktop.
WordPress template snippet to display an image from a CMB file field. Make sure you've registered your CMB field with 'save_id' => true. When the field is saved, the attachment ID will be saved in a custom field and can be accessed by appending _id to your chosen custom field id.
<?php $attachment_id = get_post_meta( get_the_ID(), '_cmb_image_id', true ); ?>
<?php if ( ! empty( $attachment_id ) ) : ?>
<?php echo wp_get_attachment_image( $attachment_id, 'thumbnail' ); ?>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment