Getting Label of Select field on a group

Support MB Group Getting Label of Select field on a group

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #36555
    Trang NguyenTrang Nguyen
    Participant

    Hi! I have a Group field (others_gr). There is a Select field (country_of_birth, single choice) inside this group.
    I tried many ways and searched for replies on the forum and this one is the best I can do to get the Label of the item in the Select field.

    $group = rwmb_meta( 'others_gr', ['storage_type' => 'custom_table', 'table' => 'mb_post_model'] );
    $select = $group['country_of_birth'];
    $group_settings = rwmb_get_field_settings( 'others_gr' );
    
    foreach ( $group_settings['fields'] as $field_settings ) {
    	$options = $field_settings['options'];
    	echo $options[ $select ];
    }

    The result shows the Label correctly but it always in double, as VietnamVietnam, JapanJapan...

    Could you please check the code above or if you have already a solution for this.
    Thank you!

    #36556
    Trang NguyenTrang Nguyen
    Participant

    Seem like the issue related to another Select field (nationality, inside the same group) which has the same list of countries as the field country_of_birth.
    Both of them get double result, but they get only one if I change the value of the options.

    #36571
    Long NguyenLong Nguyen
    Moderator

    Hi,

    If you have another select subfield with the same value and label, it will display the label twice. You need to use another value option to remove one label.

    #36575
    Trang NguyenTrang Nguyen
    Participant

    Thank you for your note.

    Just want to double check if the code I used is correct. Seem like it is not a good way because if I use a '</br>', it will create many empty lines.

    #36594
    Long NguyenLong Nguyen
    Moderator

    Hi,

    It should work. I see there is another topic about this case, please find it here https://support.metabox.io/topic/show-label-of-select-chekbox-list

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