rwmb_the_value showing up twice?

Support General rwmb_the_value showing up twice?Resolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #19645
    BrianBrian
    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!

    #19646
    Long NguyenLong 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
    BrianBrian
    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 NguyenLong 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 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.