Custom Fields
Support General Problem with rwmb_get_value

  • Creator
  • #14731
    Camilo Mejia

    I have a field like this:

      'type' => 'checkbox_list',
      'options' => array(
        'some-value' => 'Some value',
        'another-value' => 'Another value'

    rwmb_the_value() returns the values as an html ul and li list while rwmb_get_value() returns an array of keys instead of values. According to the documentation, that helper must returns an array of values, not the keys.

    I need to format the values with other html tags, but with the given helpers, there is not an option to get 'Some value' and 'Another value' in an array instead of pre formatted in html. rwmb_get_value() only gives me an array with 'some-value' and 'another-value'.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
  • #14744
    Anh Tran

    Hi Camilo,

    Actually, you are setting the field in opposite. The correct pattern should be:

    'value1' => 'Label 1',
    'value2' => 'Label 2'

    (It's the 'value' => 'Label', not 'key' => 'value').

    And the helper function returns the values, not labels.

    You can get the labels, you can do this:

    $field = rwmb_get_field_settings( 'field_id' );
    $options = $field['options'];
    // Get all labels.
    $values = rwmb_meta( 'field_id' );
    $labels = array_map( function( $value ) use ( $options ) {
        return $options[$value];
    }, $values );
    // Output labels.
    foreach ( $labels as $label ) {
        echo $label;
    Camilo Mejia

    Hi Anh

    Thanks for your help, after looking how rwmb_the_value works in the plugin code I found rwmb_get_field_settings and implemented something similar to your example. I missed it when I looked in the documentation.

    But I think it's confusing that rwmb_the_value returns labels and rwmb_get_value returns values, when both methods have similar names. What about adding an optional parameter to rwmb_get_value to choose between labels and values? Or create rwmb_get_label to get labels without html?

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