I'm trying to display thumbnails inside a div from a query, but the thumbnail is outside the div and I don't know what I'm doing wrong, here is my code:

// WP_Query arguments
$args = array(
    'post__in' => array(26844,26829),
    'post_type'              => array( 'wedstrijd' ),
    'post_status'            => array( 'published' ),

// The Query
$shquery = new WP_Query( $args );

// The Loop
if ( $shquery->have_posts() ) {
    while ( $shquery->have_posts() ) {
        echo '<div class="wed_thumb">' . the_post_thumbnail('et-pb-post-main-image') . '</div>';
} else {
    // no posts found

// Restore original Post Data

the_post_thumbnail will echo it, You should Use get_the_post_thumbnail instead to return image.

  • Thanks, that did it! Only problem now is that the size 'et-pb-post-main-image' doesn't work. Is size even possible with get_thepost_thumbnail? I also tried $size = 'et-pb-post-main-image' to no avail. – user1081953 Oct 16 at 18:17
  • get_the_post_thumbnail( $post_id, 'et-pb-post-main-image'); – techno Nov 5 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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