Custom Fields
Re-Envisioned
Support General rwmb_the_value showing up twice?

  • Creator
    Topic
  • #19645
    Resolved Brian
    Participant

    Hi Long,
    I’m trying to display the field label “not value” for my select advanced field choices.

    But when I add rwmb_the_value it displays twice? See my pastebin and screenshot. What am I doing wrong / displaying twice?

    Pastebin: https://pastebin.com/wFAXC6x9
    Screenshot: https://share.getcloudapp.com/RBuvRbX0

    Thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #19646
    Long Nguyen
    Moderator

    Hi Brian,

    To display the field label, you can use the function rwmb_get_field_settings(). Please follow this documentation https://docs.metabox.io/rwmb-get-field-settings/
    and this article https://metabox.io/get-field-settings/.

    #19647
    Brian
    Participant

    Hi Long,
    Thanks for the reply and pointing me to rwmb_get_field_settings()

    I’m getting close but still have a few errors. Is this the correct approach for displaying the labels instead of the value in a select advanced dropdown field?

    
    // Return Select Advanced field labels
        $field = rwmb_get_field_settings('dgp_holiday_availability');
        $options = $field['options'];
        
        // Get all labels
        $values = rwmb_meta('dgp_holiday_availability');
        $labels = array_map( function( $value ) use ( $options ) {
            return $options[$value];
        }, $values );
        
        // Output labels
         if ( $values = rwmb_meta( 'dgp_holiday_availability' ) ) {
         foreach ( $labels as $label ) {
            $new_content .= '<li><span class="holiday-details-label">Availability:</span>' .esc_html( $label ) . '</li>';
            }
        }
    
    #19651
    Long Nguyen
    Moderator

    Hi,

    Please try again with this code

    // Return Select Advanced field labels
    $field = rwmb_get_field_settings( 'dgp_holiday_availability' );
    $options = $field['options'];
        
    // Output labels
    foreach ($options as $key => $value) {
        echo $value . '<br>';
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
grid gear info copy caret-up caret-down trash