Skip to content

Empty repeater is not empty if containing a file field #721

@phh

Description

@phh

Expected Behavior:

The meta value of the repeater group to be empty

Actual Behavior:

Instead returning one entry in the array with a file_id field containing 0

get_post_meta(...) array(1)
  →array(1)
    'myprefix_file_id' => integer 0

Steps to reproduce (I have confirmed I can reproduce this issue on the trunk branch):

  1. Save a post without filling these data in
  2. Output the data of the meta - try to compare with version 2.2.1

CMB2 Field Registration Code:

add_filter( 'cmb2_meta_boxes', function( $meta_boxes ) {
    return [ 'prefix_my_repeater' => [
        'title'        => __( 'Fact boxes' ),
        'id'           => 'prefix_my_repeater',
        'type'         => 'group',
        'object_types' => 'post',
        'fields'       => [
            [
                'id'          => 'prefix_factbox_group',
                'type'        => 'group',
                'description' => __( 'Add multiple fact boxes to the page' ),
                'options'     => [
                    'group_title'   => __( 'Fact box {#}' ),
                    'add_button'    => __( 'Add another fact box' ),
                    'remove_button' => __( 'Remove fact box' ),
                    'sortable'      => true
                ],
                'fields' => [
                    [
                        'name' => __( 'Title' ),
                        'id'   => 'prefix_title',
                        'type' => 'text'
                    ],
                    [
                        'name' => __( 'Image' ),
                        'id'   => 'prefix_image',
                        'type' => 'file'
                    ],
                    [
                        'name' => __( 'Text' ),
                        'id'   => 'prefix_text',
                        'type' => 'wysiwyg',
                        'options' => [
                            'media_buttons' => false,
                            'teeny'         => true,
                            'textarea_rows' => 6
                        ]
                    ],
                    [
                        'name' => __( 'Link' ),
                        'id'   => 'prefix_link',
                        'type' => 'text_url'
                    ],
                    [
                        'name' => __( 'Link text' ),
                        'id'   => 'prefix_link_text',
                        'type' => 'text'
                    ]
                ]
            ]
        ]
    ] ];

    return $meta_boxes;
} );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions