Passing postid of Testimonial Custom Post in Shortcode Parameter

Well, maybe you shouldn’t set $args[‘posts id’] as this is not a supported argument for the get_posts function and instead use the “posts__in” argument or instead switch to the “get_post” function if you get the id parameter. Also, i’m not quite sure but i think you have to use quotes in the shortcode.

So your Shortcode function should look like this:

function load_testimonials($a){
     $thePostID = $post->ID;
    $args = array(
        "post_type" => "testimonials",
        "id"       =>  $post->ID
    );

    if( isset( $a['rand'] ) && $a['rand'] == true ) {
        $args['orderby'] = 'rand';
    }
    if( isset( $a['max'] ) ) {
        $args['posts_per_page'] =(int) $a['max'];
    }
    if(isset( $a['id'])){
     echo   $args['posts__in'] = array((int)$a['id']);
    }
    //getting all testimonials
    $posts = get_posts($args);

    echo '<div id="testimonials" class="flexslider">';
        echo '<ul class="slides">';

        foreach($posts as $post)
        {

            $url_thumb = wp_get_attachment_thumb_url(get_post_thumbnail_id($post->ID));
            $link = get_url($post);
            echo '<li>';
            echo '<div class="slide-testimonials">';
                if ( ! empty( $url_thumb ) ) { echo '<img src="'.$url_thumb.'" />'; }
                if ( ! empty( $post->post_content ) ) { echo '<p>'.$post->post_content.'<br />'; }
                echo '<h2>'.$post->post_title.'</h2>';
                if ( ! empty( $link ) ) { echo '<a href="'.$link.'">Visit Site</a></p>'; }
            echo '</div>';
            echo '</li>';
        }

        echo '</ul>';
    echo '</div>';
}

and then call it like this:

<?php echo do_shortcode('[testimonials id="3751"]'); ?>

Happy Coding,

Kuchenundkakao

tech