Option source function in advanced select

Support MB Builder Option source function in advanced selectResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #30886
    tim27tim27
    Participant

    Hello,
    I have a problem to get values in a checkbox-list. Already red some articles here and in the documentation (https://docs.metabox.io/fields/checkbox-list/#template-usage)

    On the user side, I have this field:

    [
        'name'              => 'Vehicles',
        'id'                => $prefix . 'vehicles',
        'type'              => 'text_list',
        'options'           => [
            'VW'    => 'Brand',
            'Golf'  => 'Name',
            'Black' => 'Color',
        ],
        'clone'             => true,
        'sort_clone'        => true,
        'clone_as_multiple' => true,
        'max_clone'         => 3,
    ],

    How can I access those user specific values?
    Tried it whit:

    [
        'name'            => 'Select Vehicles',
        'id'              => $prefix . 'selected_vehicles',
        'type'            => 'select_advanced',
        'options'         => getVehicles(),
        'multiple'        => true,
        'select_all_none' => true,
    ],

    ...

    function getVehicles() {
        $values = rwmb_meta( 'vehicles', ['object_type' => 'user'], $user->ID );
        foreach ( $values as $value ) {
            return $value;
        }
    }

    But nothing cames back... 🙁
    I'dont have any other ideas. Thanks for supporting me!

    #30894
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Because the helper function rwmb_meta() is executed after the action hook rwmb_meta_boxes so it will not work. If you want to retrieve user meta when register meta boxes and custom fields, please use the function get_user_meta().

    And the function should return an array of 'value' => 'Label' pairs. Please read more here https://docs.metabox.io/fields/select-advanced/#settings

    #30897
    tim27tim27
    Participant

    Thank you, I'll try it!

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