WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to display a thumbnail in a foreach loop. The thumbnail is a new image size I have added called "plant-thumb". I have all the desired elements displaying properly except for the thumbnail. Here is my code:

      foreach ( $posts as $post ) {   

       echo '<a class="modalLink" href="plant-list-accordion'.$post->ID.'" >';
       echo get_the_post_thumbnail($thumbnail->ID, 'plant-thumb'); //Here is where I'm trying to output the bespoke thumbnail
       echo '</a>';

            $faq .= sprintf(('<div class="modal mfp-hide" id="plant-list-accordion'.$post->ID.'">%1$s<div>%2$s</div>'),
            $faq .= '</div>'; //Close the container

        return $faq; //Return the HTML.
share|improve this question
up vote 0 down vote accepted

echo get_the_post_thumbnail($post->ID, 'plant-thumb');

share|improve this answer
Please add an explanation to your answer: why could that solve the problem? – toscho Jul 25 '13 at 11:28
wonderful, thank you – Ciaran Gaffey Jul 25 '13 at 11:28
This is exactly what I needed, thank you! – TheLibzter Jan 12 '15 at 20:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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