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:
Where
is the group field id and
for example is the inside field id.
<strong>My question is:</strong>
Assuming that code is working why wouldn't this code work also:
?
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?
Now when you want to echo this field the wiki of "CMB2" says you'll use this:
Code:
$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
Code:
wiki_test_repeat_group
Code:
title
<strong>My question is:</strong>
Assuming that code is working why wouldn't this code work also:
Code:
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?