0

I am having trouble displaying my image in a repeatable group. I am able to display all fields except the image.

Here is the code to display a repeatable group

 $meta_boxes['project_metaboxpress'] = array(
      'id'         => 'project_metaboxpress',
      'title'      => __( 'Press Information', 'cmb' ),
      'pages'      => array( 'press', ), // Post type
      'context'    => 'normal',
      'priority'   => 'high',
      'show_names' => true, // Show field names on the left
      // 'articles_styles' => true, // Enqueue the articles stylesheet on the frontend
 'fields'     => array(
        array(
           'id'          => $prefix . 'articles',
           'type'        => 'group',
           'description' => __( 'Articles Printed', 'cmb' ),
           'options'     => array(
           'group_title'   => __( 'Article {#}', 'cmb' ),
           'add_button'    => __( 'Add Another Article', 'cmb' ),
           'remove_button' => __( 'Remove Article', 'cmb' ),
           'sortable'      => true, // beta
      ),
      'fields'  => array(
            array(
                'name' => 'Title',
                'id'   => 'title',
                'type' => 'text',
                'description' => '',
             ),
             array(
                'name' => 'Date Published',
                'desc' => '',
                'id'   => $prefix . 'date',
                'type' => 'text_date'
             ),
             array(
                'name'    => 'Print Type',
                'desc'    => 'Select an option',
                'id'      => $prefix . 'printType',
                'type'    => 'select',
                'options' => array(
                     'Select'   => __( 'Select Print Type', 'cmb' ),
                     'Print'       => __( 'Print', 'cmb' ),
                     'Online'   => __( 'Online', 'cmb' ),
            ),
            'default' => 'custom',
        ),
        array(
            'name'  => 'Upload Article',
            'desc'  => 'Upload an image or enter an URL.',
            'id'    => $prefix . 'image',
            'type'  => 'file',
            'allow' => array( 'url', 'attachment' ) // limit to just attachments with array( 'attachment' )
            ),
        ),
        ),
    ),
);

Displaying on the front-end

  <div id="products" class="list clearfix">
  <?php global $post; $entries = get_post_meta( get_the_ID(), '_cmb_articles', true ); foreach ( $entries as $key => $entry ) {?>
        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <div class="left">
                <h4>Article Title</h4>
                <span><?php echo $entries [$key]['title'];?></span>
            </div>
            <div class="left">
                <h4>Date Published</h4>
                <span><?php echo $entries [$key]['_cmb_date'];?></span>
            </div>
            <div class="left">
                <h4>Print Type</h4>
                <span><?php echo $entries [$key]['_cmb_printType'];?></span>
            </div> 
            <div class="left">
                <ul>
                    <li><?php echo $img [$key]['_cmb_image'];?></li>
                    <li class="icon-pencil"><?php edit_post_link('','',' '); ?></li>
                </ul>                    
            </div>
        </article>          
  <?php } //endforeach ?>
  </div>

echo $img [$key]['_cmb_image']; is what I am using to try and display my image but I can not get it to work. Any help would be great

  • have you read get_post_meta in codex? – Milo Aug 4 '14 at 16:18
  • I have, but I can't seem to figure out how to combine it with the code I have @Milo – user3756781 Aug 4 '14 at 16:20

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.