0

I've been trying to get the post thumbnail to display in the foreach loop for a few hours now and I can't figure out how to make it work, any help would be greatly appreciated!

          <div id="home-posts" class="col-sm-3" role="complementary">

          <div class="recent-post-sidebar">

          <h3>Popular Posts</h3>

         <?php 
                $popular_post_object = new WDS_JetPack_Popular_Posts( array( 
                            'count' => 5, 
                            'days' => 200, 
                            'transient_affix' => '_mypp')) ;?>

          <?php $popular_post_results = $popular_post_object->get_posts();?>

          <?php if ( !empty( $popular_post_results ) ) { 

    foreach( $popular_post_results as $popular_post ) {

        echo '<a href="' . $popular_post['permalink'] . '">';
        echo '<div class="post one">';
        echo '<div class="post overlay"></div>';
        echo  get_the_post_thumbnail($popular_post->ID, 'wpbs-featured-full');
        echo'<h5>'. $popular_post['title'] .'</h5>';
        echo '</div>';
        echo '</a>';

    }
}?>

       </div>

       </div>

The original source of the code is WebDevStudios.

1 Answer 1

2

If you read the documentation that you have linked to, you would see that the post ID is stored in the array key post_id and not ID.

You should then change

get_the_post_thumbnail($popular_post->ID, 'wpbs-featured-full');

to

get_the_post_thumbnail($popular_post['post_id'], 'wpbs-featured-full');
1
  • My pleasure, enjoy :-) Commented Nov 4, 2015 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.