Setting a cloneable group value for a post

Support MB Frontend Submission Setting a cloneable group value for a post

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36886
    vacdkvacdk
    Participant

    Hi

    im really struggling with the documentaion of Setting a cloneable group value for a post.

    I have the following settings:

    Field Group ID: ticket-addon
    Group ID: group_tapgyiu2mz
    Sub field ID: ticket_extra

    When using this code its not working:

    $field_id = 'ticket_extra';
    $value = rwmb_meta( 'group_tapgyiu2mz', '', $post_id );
    $value['ticket_extra'] = '2025';
    rwmb_set_meta( $post_id, $field_id, $value );

    But i get this output:
    Array ( [0] => Array ( [ticket_price] => 1 [ticket_extra] => 999 [_state] => expanded ) [ticket_extra] => 2025 )

    If i use this code from the documentation:

    $field_id = 'ticket_extra';
    $value = [['ticket_extra' => '2025',],];
    rwmb_set_meta( $post_id, $field_id, $value );

    Then i get this output, but still not working
    Array ( [0] => Array ( [ticket_extra] => 2025 ) )

    It says in the documentation to use $field_id, but what is the field id in a clonable group ?
    Is it the:
    Field Group ID: ticket-addon
    Group ID: group_tapgyiu2mz
    Sub field ID: ticket_extra

    I tried all, but still not working.

    If i just create a normal text field and use this code:

    $field_id = 'test_field';
    $value = '2025';
    rwmb_set_meta( $post_id, $field_id, $value );

    Then its working fine...

    #36898
    Long NguyenLong Nguyen
    Moderator

    Hi,

    To update the value in the multidimensional array, you need to point to all indices. For example

    $value[0]['ticket_extra'] = '2025';

    then the field ID that needs to update is the group ID, not the subfield ID

    rwmb_set_meta( $post_id, 'group_tapgyiu2mz', $value );

    Basic knowledge of PHP coding is needed to control the group value in this case, you can read more here https://www.phptutorial.net/php-tutorial/php-multidimensional-array/

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