Trouble using get_post

For Microkids related post plugin
He said

“Using the get_post() function you could get any data you need from
the related posts.”

Read More

and he posted this snippet of code.

$related_posts = MRP_get_related_posts( $post_id );

I’m not exactly sure how to use the get_post feature for this situation. I would like to display the titles and thumbnail for each post in that array. Any help would be appreciated.

Related posts

Leave a Reply

3 comments

  1. possibly:

    $related_posts = MRP_get_related_posts( $post->ID );   
        if( $related_posts ) foreach( $related_posts as $key=>$value ) { 
            //only holds the following information:
            //echo $key; //the related_post_id  
            //echo $value;  //the related post title
            echo get_the_title($key);     
            echo get_the_post_thumbnail($key);   
        }
    

    (edited after downloading and testing the plugin)

  2. this worked for me:

    <?php
        global $post;
        $post_type = ( $instance['post_type'] == 'all' ) ? null : $instance['post_type'];
        $related_posts = MRP_get_related_posts( $post->ID, 0, 0, $post_type );
        if( $related_posts ) {
            echo "<div id='boxes'><div class='container'> n";
            foreach( $related_posts as $related_post_id => $related_post_title  ) {
                if ( '' != get_the_post_thumbnail($related_post_id) ) {
                    $thumb_id = get_post_thumbnail_id($related_post_id);
                    $thumb_url = wp_get_attachment_image_src($thumb_id, true);
                    $theImage = $thumb_url[0];
                } else {
                    $theImage = get_bloginfo('stylesheet_directory').'/img/trama-01.gif';
                }
                echo '<div class="box simple" style="background-image:url('.$theImage.')"><div class="box-content"><div class="wrapper"><div class="cover">';
                echo "<div class='titulo'><a href="".get_permalink( $related_post_id ).""><h3>".get_post_meta($post->ID,'wpcf-tagline',TRUE)."</h3><h1>".$related_post_title."</h1></a></div>";
                echo "</div></div></div></div>n";
            }
            echo "</div></div>";
        }
    ?>
    

    The markup I needed to achieve was:

    <div class='box simple' style="background-image:url(../img/banner-01.jpg)">
        <div class='box-content'>
            <div class='wrapper'>
            <div class='cover'>
                <div class="titulo">
                            <a href="#">
                                <h3>WP Types Tagline custom field here</h3>
                                <h1>Title here</h1>
                            </a>
                        </div>                    
                    </div>
                 </div>
            </div>
    </div>
    

    Hope it helps someone,

    Best.