How to get a label from a select field that is in a sub group field?

Support MB Group How to get a label from a select field that is in a sub group field?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #24344
    Dobos DánielDobos Dániel
    Participant

    Hi,
    I have a sub group field in which I have a select field. How can I get label from the select field? I have a value, but i need a label.

    I found this code, but I need it in the sub group version.

    $parts_name = rwmb_meta( 'group' );
    $group_settings = rwmb_get_field_settings( 'group' );
    $select_settings = $group_settings['fields']['select_field_id'];
    foreach ( $parts_name as $part_name ) {
        $value = $part_name['item'];
        $label = $select_settings['options'][$value];
        echo $label;
    }

    Thank you

    #24353
    Long NguyenLong Nguyen
    Moderator

    Hi Dobos,

    Please follow this topic to get the label of the sub-field select in a group https://support.metabox.io/topic/show-label-of-select-chekbox-list/.

    Let me know if it helps.

    #24425
    Dobos DánielDobos Dániel
    Participant

    Hi,

    This code works perfectly for me too:

    $group1 = rwmb_meta( 'dbg_group_cpt_ital_alapanyag' );
    $group1_settings = rwmb_get_field_settings( 'dbg_group_cpt_ital_alapanyag' );
    
    foreach ( $group1 as $group1_value ) {
        $group2 = $group1_value['dbg_sub_group_cpt_ital_alapanyag'];
        
        foreach ( $group2 as $group2_value ) {
            $multi_select = $group2_value['ital_alapanyag_mertekegyseg'];
            foreach ( $multi_select as $select_value ) {
                foreach ( $group1_settings['fields'] as $group1_field_settings ) {
                    if( array_key_exists( 'fields', $group1_field_settings ) ) {
                        foreach ( $group1_field_settings['fields'] as $field_settings ) {
                            foreach ( $field_settings as $setting_key => $setting_value ) {
                                if ( $setting_key == 'options' ) {
                                    echo $setting_value[$select_value];
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    Can I find somewhere a version for single choices?

    Thank you

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