Output radio button value in repeatable group
-
Hey Folks,
I’m trying to output a radio button value in a repeated group, but I can’t make it go. I’m sure it’s user error, but I need some help. I can output a non-grouped radio button, but don’t know how to get a group radio button value. Code below.
// CMB2 - Homepage Custom Content add_action( 'cmb2_admin_init', 'hp_mb' ); /** * Define the metabox and field configurations. */ function hp_mb() { // Start with an underscore to hide fields from custom fields list $prefix = '_bto_'; /** * Initiate the metabox */ $cmb = new_cmb2_box( array( 'id' => 'hp_custom_content', 'title' => __( 'Homepage Custom Content', 'cmb2' ), 'object_types' => array( 'page' ), // post type 'show_on' => array('key' => 'id', 'value' => array(5)), 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left ) ); // Learn More $group_field_id = $cmb->add_field(array( 'id' => 'learn_more_group', 'type' => 'group', 'options' => array( 'group_title' => _('Learn More Item {#}'), 'add_button' => _('Add another item'), 'remove_button' => _('Remove item'), 'sortable' => true, ), )); $cmb->add_group_field( $group_field_id, array( 'name' => 'Is this a wide image, narrow image or video?', 'id' => 'img_title', 'desc' => '<b>If it is a video, please skip to the video section</b>.', 'type' => 'radio', 'show_option_none' => false, 'options' => array( 'wide' => 'Wide Image', 'narrow' => 'Narrow Image', 'video' => 'Video', ), )); }
Output
<?php $boxes = get_post_meta( get_the_ID(), 'learn_more_group', true ); foreach ( (array) $boxes as $box => $entry ) { $img = $option = ''; if ( isset( $entry['img_title'] ) ) { $option = $entry['img_title']; } if ( isset( $entry['item_img'] ) ) { $img = wp_get_attachment_image( $entry['item_img_id'], 'share-pic', null, array( 'class' => 'large', ) ); } echo $option; echo $img; } ?>
Thanks,
Adam
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Output radio button value in repeatable group’ is closed to new replies.