Custom Fields
Re-Envisioned
Support Meta Box Group sub group gets only one value

  • Creator
    Topic
  • #8887
    Phaidonas
    Participant

    Hello, 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>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #8907
    Anh Tran
    Keymaster

    Hi,

    The files field is a sub-group of the press_group, so you should not get sub-group’s value directly with rwmb_meta. Instead, get the value from the parent group press_group, like this:

    $group = rwmb_meta( 'press_group' );
    $files = isset( $group['Press_Files_group'] ) ? $group['Press_Files_group'] : array();
    print_r( $files );
    #8909
    Phaidonas
    Participant

    i 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

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘sub group gets only one value’ is closed to new replies.