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

Support MB Group How to get a label from a select_advanced field that is in a group field?Resolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #18023
    MartinJaneekMartinJaneek
    Participant

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

    my current code:

    <?php
    $parts_name = rwmb_meta('group', $args = ' ', $post_id = $post->ID);
    foreach ($parts_name as $part_name) : 
                echo $part_name['item'];
    endforeach
    ?>

    group ID -'group'
    select_advanced ID - 'item'

    Thank you

    #18033
    Anh TranAnh Tran
    Keymaster

    Hi Martin,

    The helper function doesn't return labels for the field, but only values. You can get the label with this code:

    $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;
    }
    #18832
    MartinJaneekMartinJaneek
    Participant

    Thank you.

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