Image Select

Support General Image Select

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #35551
    uptwouptwo
    Participant

    Hey!

    Is there no way to get the image select as an array?

    rwmb_the_value returns an unordered list,
    rwmb_meta/rwmb_get_value returns the saved database value

    So we only have the options to display an ul with the images selected, but can't modify e.g. the class of the or just the label but not the url.

    Is there no way to return something like this?

    [
    'choice 1' => '/url/to/image.png',
    'choice 2' => '/url/to/image2.png',
    'choice 3' => '/url/to/image3.png',
    ]
    

    Seems strange to me or am i missing something?

    #35552
    uptwouptwo
    Participant

    Is that the only way?

    
    $selectedOptions = rwmb_meta('field_id', '', $post_id);
    $allOptions = rwmb_get_field_settings('field_id', '', $post_id)['options'];
    $imgs = array_intersect($selectedOptions, array_keys($allOptions));
    foreach ($imgs as $img) {
    echo '<img src="' . $allOptions[$img] . '" style="width: 100px; height: 100px; object-fit:contain;"
    loading="lazy">';
    }
    #35572
    Long NguyenLong Nguyen
    Moderator

    Hi,

    The field image_select works like the field radio or checkbox, which means it saves the value to the database and uses images for friendly selection. If you want to get the label of the selection (image URL), please use the helper function rwmb_get_field_settings() like your sample code.
    https://docs.metabox.io/rwmb-get-field-settings/

    #35589
    uptwouptwo
    Participant

    Thank you for your reply!

    Would be good if there would be an option to save the labels/url as well. For now it seems overly complicated and the image select field seems to be only for cosmetic purposes and not really for "selecting images"(atleast, if you have value => url)

    Have a great day!

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