I am using the "CMB2" wordpress plugin to add custom fields. and there is an option to add group field and add fields to it.
Now when you want to echo this field the wiki of "CMB2" says you'll use this:
$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
}
Where wiki_test_repeat_group is the group field id and title for example is the inside field id.
My question is: Assuming that code is working why wouldn't this code work also:
echo get_post_meta( get_the_ID(), 'wiki_test_repeat_group', true )[title];
?
And is there another way i could get one field with a short one line code and not use the foreach loop for getting just one field?