Hey Ben,
This sample code registers a group of fields: contact name, contact email, contact phone number:
add_filter( 'rwmb_meta_boxes', 'prefix_register_contacts' );
function prefix_register_contacts( $meta_boxes ) {
$meta_boxes[] = array(
'title' => __( 'Contacts', 'textdomain' ),
'post_types' => 'post',
'fields' => array(
array(
'id' => 'contacts',
'type' => 'group',
'clone' => true,
'fields' => array(
array(
'id' => 'name',
'type' => 'text',
'name' => __( 'Name', 'textdomain' ),
),
array(
'id' => 'email',
'type' => 'text',
'name' => __( 'Email', 'textdomain' ),
),
array(
'id' => 'phone',
'type' => 'text',
'name' => __( 'Phone', 'textdomain' ),
),
),
),
),
);
return $meta_boxes;
}
In the single.php
, you can add the following code to display contacts:
$contacts = rwmb_meta( 'contacts' );
if ( ! empty( $contacts ) ) {
foreach ( $contacts as $contact ) {
echo '<div class="contact">';
echo '<h4>', __( 'Contact info', 'textdomain' ), '</h4>';
echo '<p><label>', __( 'Name:', 'textdomain' ), '<label> ', $contact['name'], '</p>';
echo '<p><label>', __( 'Email:', 'textdomain' ), '<label> ', $contact['email'], '</p>';
echo '<p><label>', __( 'Phone number:', 'textdomain' ), '<label> ', $contact['phone'], '</p>';
echo '</div>';
}
}