Skip to content

Saving "dynamic" WYSIWYG fields doesn't work #395

@chrishandy9

Description

@chrishandy9

Hi, I have created a textbox that accepts user input to decide how many additional boxes to display, once that number is entered and saved, the edit post page reloads and displays the amount of WYSIWYG boxes as requested. Upon saving the post, nothing gets updated/inserted into the database. The $_POST data appears in the object if dumped, but it doesn't make it to the database.

I manually added each box instead of looping through them (with the same ID as if they were being looped through) and it saved the post meta fine. My code is as follows:

$cmb = new_cmb2_box(array(
    'id'            => 'num_slides_box',
    'title'         => __( 'Enter number of slides', 'cmb2'),
    'object_types'  => array('post'), //post type
    'context'       => 'normal',
    'priority'      => 'high',
    'show_names'    => 'true',//show the field names on the left
) );
$slideNum = get_post_meta($post_id, 'num_slides', true);
for ($i = 0; $i < $slideNum; $i++) { 
    $cmb->add_field(  array(
        'id'        => 'slider_group_'.$i,
        'name'      => 'Slide',
        'desc'      => 'Side contents'.$i,
        'type'      => 'wysiwyg',
        'options'   => array(),
    ) );
}

Is there a reason as to why it won't save fields that have been looped through?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions