Return multiple values ​in a shortcode attribute

Question

Today the shortcode I created below is working normally if I pass only one value, however, now I am trying this shortcode so that the attribute can receive multiple values. The idea is for the shortcode to look like this: [youlike id_post = '6059, 76912']. I tried to add it like this in the post, but it didn’t work.

Below the function I have

function youCanLike( $atts ) {
    ob_start();
    
    $value = shortcode_atts( array(
        'id_post' => '',
    ), $atts );

    // Check if href has a value before we continue to eliminate bugs
    if ( !$value ['id_post'] )
        return false;

    $args = array(
        'post__in' => array( esc_attr( $value['id_post'] ) ),
        'orderby' => 'date',
        'order' => 'DESC'
    );

    get_template_part( 'global-templates/blocks/block', 'you-can-like', $args );

    return ob_get_clean();   
} 
add_shortcode( 'youlike', 'youCanLike' );

And this is where the get_template_parte file is calling.

<div class="content-box--primary">
    <h2 class="content-box--primary__head">You may also be interested:</h2>
    
        <?php
        
        $args = wp_parse_args( $args );

        $query = new WP_Query( $args );

        if( $query->have_posts() ):
            while( $query->have_posts() ): $query->the_post();

        ?>

    <article class="content-box--primary__content">
        <a href="<?php the_permalink(); ?>" class="content-box--primary__link">
            <h3 class="content-box--primary__title"><?php the_title(); ?></h3>
            <span class="content-box--primary__more">Read More</span>   
        </a>
    </article>

    <?php
        endwhile;
        wp_reset_postdata();
        endif;                                  
    ?>

</div>
0
Renan Bessa 2 months 0 Answers 14 views 0

Leave an answer