update_post_meta for cloneable fields in a group.

Support Meta Box AIO update_post_meta for cloneable fields in a group.Resolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #39197
    Macky McCormackMacky McCormack
    Participant

    Hi,

    I'm trying to get this to work but for some reason its not. Here's my fields

    
    $meta_boxes[] = [
            'title'      => __( 'Order Details', 'your-text-domain' ),
            'id'         => 186,
            'post_types' => ['fr_order'],
            'style'      => 'seamless',
            'fields'     => [
                [
                    'name'   => __( 'Guest Names', 'your-text-domain' ),
                    'id'     => $prefix . 'fr_guest_names',
                    'type'   => 'group',
                    'fields' => [
                        [
                            'name'  => __( 'Guest Name', 'your-text-domain' ),
                            'id'    => $prefix . 'fr_guest_name',
                            'type'  => 'text',
                            'clone' => true,
                        ],
                    ],
                ],
            ];
    

    and here's my code for updating:

    
    $post_meta = Array
    (
        [0] => Array
            (
                [fr_guest_name] => Amet tempor nisi
            )
    
        [1] => Array
            (
                [fr_guest_name] => Condimentum a
            )
    
        [2] => Array
            (
                [fr_guest_name] => Mollis sed posue
            )
    
        [3] => Array
            (
                [fr_guest_name] => Arcu a eget euis
            )
    )
    
    update_post_meta($order_id, 'fr_guest_names', $post_meta);
    

    The post has already been created and the $order_id is the wp post id.

    I get a meta ID returned from the update_post_meta function but the names don't show up in the admin area:

    https://www.dropbox.com/s/luoigwe59tqzq3x/metaboxclonablegroup.JPG?dl=0

    Can you help?

    #39205
    PeterPeter
    Moderator

    Hello Macky,

    The clone field in your code is the text field, not the group. So the variable $post_meta will look like this

    $post_meta = Array
    (
        [fr_guest_name] => Array
            (
                [0] => Amet tempor nisi,
                [1] => Condimentum a,
                [2] => Mollis sed posue
            )
    )

    You can add add a test field value for a post manually, then get field value from the database and output the value with the function var_dump() or print_r() to see the value structure.

    #39292
    Macky McCormackMacky McCormack
    Participant

    Hi Peter,

    Thanks for your help, this worked

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.