Shortcode with attributes returns the default value of the attributes

Question

This shortcode below always returning the default values of my attributes. I cant find the mistake.

function leweb_get_event_details( $args ) {

    ob_start();

    $atts = shortcode_atts( array(
                'field'   => 'event_budget',  
                'label'   => '',
                'single'  => true,
    ) , $atts );    

    // Attribute
    $label = $atts['label'];
    $value = get_post_meta( get_the_ID(), $atts['field'], $atts['single'] );
    $single = $atts['single'];

    if( $single === true ) {

        return $value;

    }

    if( $single === false ) {

        return print_r( $value );

    }

    $output = ob_get_clean();
    return $output;

}
add_shortcode( 'leweb_get_event_details', 'leweb_get_event_details' );

The shortcode:

Time: [leweb_get_event_details field="event_time_to"]

Musikstile: [leweb_get_event_details field="event_musikstil"]

The output on frontend is the default value from ‘field’…

0
, LovinQuaQua 2 years 2019-10-27T15:19:39-05:00 0 Answers 88 views 0

Leave an answer

Browse
Browse