Storing cloneable group with datetime field programmatically

Support MB Group Storing cloneable group with datetime field programmatically

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #40289
    LRLR
    Participant

    Hi,

    I've tried the solution described in https://support.metabox.io/topic/replace-array-value-in-group/ but it doesnt work for me.

    My field configuration:

    $meta_boxes[] = [        
            'id'         => 'provider_management',
            'fields'     => [
                [
                    'id'                => 'provider_management_group',
                    'type'              => 'group',
                    'clone'             => true,
                    'sort_clone'        => true,
                    'fields'            => [
                        [
                            'id'        => 'provider_management_group_date',
                            'type'      => 'datetime',
                            'timestamp' => true,
                        ],
                        [
                            'id'      => 'provider_management_group_note',
                            'type'    => 'textarea',
                        ],
                    ],
                ],
            ],
        ];

    Storing values I have tried:

    $values = [];
    $values[] = [ 'provider_management_group_date' => [ 'timestamp' => time(), 'formatted' => date('Y-m-d H:i', time()) ], 'provider_management_group_note' => $admin_note ];

    or just:

    $values = [];
    $values[] = [ 'provider_management_group_date' => time(), 'provider_management_group_note' => $admin_note ];

    And tried saving it with:

    rwmb_set_meta( $object_id, 'provider_management_group', $values );

    or

    update_post_meta( $object_id, 'provider_management_group', $values );

    But it doesn't save, or it doesnt show afterwards in the edit post area.

    Any idea what I am doing wrong here?

    #40321
    PeterPeter
    Moderator

    Hello,

    Can you please share the code that you use to update the group field value? I see it works as well on my demo site. Here is an example:

    add_action( 'init', function() {
        $values = [];
        $values[0] = [ 'provider_management_group_note' => 'asdf1234' ];
        $values[1] = [ 'provider_management_group_note' => '1234asdf' ];
        rwmb_set_meta( 67516, 'provider_management_group', $values );
    }, 99 );
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.