sub group gets only one value
- This topic has 2 replies, 2 voices, and was last updated 7 years, 1 month ago by
Phaidonas.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
March 20, 2018 at 6:51 PM #8887
Phaidonas
ParticipantHello, i have created a sub-group, but only returns and saves one value, also in the post page, when i update only saves the last. Here is the code:
function press($meta_boxes) { $meta_boxes[] = array( 'title' => 'Press Details', 'post_types' => array( 'personal_projects' ), 'fields' => array( array( 'id' => 'press_group', 'type' => 'group', 'fields' => array( array( 'id' => 'press_wysiwyg', 'name' => esc_html__('Press Text', 'metabox-online-generator'), 'type' => 'wysiwyg', ), array( 'id' =>'press_image_advanced', 'type' => 'image_advanced', 'name' => esc_html__('Press Images', 'metabox-online-generator'), ), array( 'id' =>'press_oembed', 'clone' => true, 'type' => 'oembed', 'name' => esc_html__('Press Video(s)', 'metabox-online-generator'), 'desc' => esc_html__('oEmbed description', 'metabox-online-generator'), 'add_button' => esc_html__('New Press video', 'metabox-online-generator'), ), array( 'name' => 'Press Files', 'id' => 'Press_Files_group', 'type' => 'group', 'clone' => true, 'fields' => array( array( 'id' =>'press_name_file', 'type' => 'text', 'name' => esc_html__('Text', 'metabox-online-generator'), 'desc' => esc_html__('Press Upload File name', 'metabox-online-generator'), ), array( 'id' =>'press_file_input_2', 'type' => 'file_input', 'name' => esc_html__('Press Files', 'metabox-online-generator'), ), ), ), ), ), ), ); return $meta_boxes; }
And the output is here:
<div class="press-text"> <?php $group_press_files = rwmb_meta('Press_Files_group'); print_r( $group_press_files); debug_to_console($group_press_files); foreach($group_press_files as $group_press_file) { echo $group_press_file; debug_to_console($group_press_file); } ?> </div>
March 21, 2018 at 8:56 AM #8907Anh Tran
KeymasterHi,
The files field is a sub-group of the
press_group
, so you should not get sub-group's value directly withrwmb_meta
. Instead, get the value from the parent grouppress_group
, like this:$group = rwmb_meta( 'press_group' ); $files = isset( $group['Press_Files_group'] ) ? $group['Press_Files_group'] : array(); print_r( $files );
March 21, 2018 at 3:16 PM #8909Phaidonas
Participanti used this kind of method:
<?php $group_press = rwmb_meta('press_group'); $group_press_files = $group_press['press_files_group']; foreach($group_press_files as $group_press_file){ echo '<a href="',$group_press_file['press_file_input_2'],'">',$group_press_file['press_name_file'],'</a>'; } ?>
But thanks
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- The topic ‘sub group gets only one value’ is closed to new replies.