Displaying Custom Meta Box field values in theme
<h1>Display Group Data is extremely Simple:</h1>
<?php
// Create the metabox
`$meta_boxes[] = array
(
'title' => 'Questions',
'pages' => 'people',
'fields' => array
(
array
(
'id' => 'gp', // this is the group ID not the group fields ID!!!
'name' => '',
'type' => 'group',
'repeatable' => true,
'sortable' => true,
'fields' => $group_fields
)
)
);`
// gp is the group id
// the last parameter must be set to false as it not single
$question_group = get_post_meta( $post->ID, 'gp', FALSE );
// Loop Through The Fields Group
foreach ($question_group as $q)
{
echo $q['question']; // The Question field
echo $q['answer']; // The Answer Field
}
?>
<h1> Display Repeating Fields</h1>
<?php
/* phone is the field id, do not use field name because
field name refers to the title displayed above the field */
$phones = get_post_meta( $post->ID, 'phone', FALSE );
// Display Number(s)
echo '<p><strong>Phone Number(s)</strong><br/>';
foreach ($phones as $number) {
echo $number.' ';
}
echo '</p>';
?>
<h1>Displaying Single Fields</h1>
<?php
$first_name = get_post_meta( $post->ID, 'first_name', TRUE );
// Set to true because its not a repeating field and true means its single
echo '<h3>'.$first_name.' '.$last_name.'</h3>';
?>