Custom Fields
Re-Envisioned
Support Meta Box Builder Option source function in advanced select

  • Creator
    Topic
  • #30886
    Resolved tim27
    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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #30894
    Long 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
    tim27
    Participant

    Thank you, I'll try it!

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