Showing Repeatable Group
-
Hello,
I am trying to add repeatable fields but I can not get the group to display on the front end. For testing purposes I have added the example from the wiki to my theme but still nothing appears.
The data saves in the backend and I can see see it in the database as well. I have other cmb2 fields that are working correctly so I’m kind of at a loss.
Code I’m using
$group_field_id = $cmb->add_field( array( 'id' => 'wiki_test_repeat_group', 'type' => 'group', 'description' => __( 'Generates reusable form entries', 'cmb' ), 'options' => array( 'group_title' => __( 'Entry {#}', 'cmb' ), // since version 1.1.4, {#} gets replaced by row number 'add_button' => __( 'Add Another Entry', 'cmb' ), 'remove_button' => __( 'Remove Entry', 'cmb' ), 'sortable' => true, // beta // 'closed' => true, // true to have the groups closed by default ), ) ); // Id's for group's fields only need to be unique for the group. Prefix is not needed. $cmb->add_group_field( $group_field_id, array( 'name' => 'Entry Title', 'id' => 'title', 'type' => 'text', // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types) ) ); $cmb->add_group_field( $group_field_id, array( 'name' => 'Description', 'description' => 'Write a short description for this entry', 'id' => 'description', 'type' => 'textarea_small', ) ); $cmb->add_group_field( $group_field_id, array( 'name' => 'Entry Image', 'id' => 'image', 'type' => 'file', ) ); $cmb->add_group_field( $group_field_id, array( 'name' => 'Image Caption', 'id' => 'image_caption', 'type' => 'text', ) );Front end code:
<?php $entries = get_post_meta( get_the_ID(), 'wiki_test_repeat_group', true ); foreach ( (array) $entries as $key => $entry ) { $img = $title = $desc = $caption = ''; if ( isset( $entry['title'] ) ) $title = esc_html( $entry['title'] ); if ( isset( $entry['description'] ) ) $desc = wpautop( $entry['description'] ); if ( isset( $entry['image_id'] ) ) { $img = wp_get_attachment_image( $entry['image_id'], 'share-pick', null, array( 'class' => 'thumb', ) ); } $caption = isset( $entry['image_caption'] ) ? wpautop( $entry['image_caption'] ) : ''; // Do something with the data echo $title; //print_r($entry); } ?>I only get blank line also when trying out print_r. Any help or direction would be appreciated.
Thanks
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
The topic ‘Showing Repeatable Group’ is closed to new replies.