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 using a homepage sorter to arrange the posts on the front page of my site because of that, I am getting the posts in this manner so that I can call each post individually instead of in a foreach loop

    $args = array( 'numberposts' => -1,'category_name' => 'homepage');
$home_post = get_posts( $args );
$image = get_the_post_thumbnail($post->ID);
global $more;
$more = 0;

Then I can call each post this way

<?php if( isset( $home_post[1] ) ) { ?>
 <p><?php echo $home_post[1]->post_excerpt; ?></p>
 <?php } ?>

My problem is that get_posts has no way to get the post thumbnail outside of using a loop. I can't use a loop because I need my post called in a switch statement. I can't find a way to get the post thumbnail. Do you know of a way?

share|improve this question
Please spend some time with a PHP tutorial. Your question is so basic I was almost ashamed to write an answer. – toscho Aug 22 '12 at 5:18
up vote 1 down vote accepted

get_the_post_thumbnail() expects the post ID as first parameter. So you need a post object like … $home_post[1].

echo get_the_post_thumbnail( $home_post[1]->ID );

… should do what you need.

share|improve this answer
Although I do appreciate your assistance with my issue, I feel as though any good will you earned was colored by your comment above. Please do not assume that a person can achieve any goal just because someone else wrote a tutorial on the subject. I did try passing the ID to the post, I just did it wrong. I am still trying very hard to learn php and people who know it can make it easier or harder. Try to be the good sport and make it easier. Your answer did give me an Aha moment and I did learn something. So for that, I thank you. – Jamie Aug 22 '12 at 22:59
@Jamie Please don’t get me wrong. Everybody has to start somewhere, I respect that. But I have to keep in mind how any question can help future visitors. Very localized or simple questions rarely do that. The core of this problem is: Every variable with an -> is an object. That’s not even WordPress specific. :) Besides that … English is my third language. I might sound harsh sometimes unintentionally. – toscho Aug 23 '12 at 1:33

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.