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

As you know the result of the the_post_thumbnail() is an image tag. I need this image tag to store at a kind of collection or Array. I'm using the following code but it doesn't help me out. And I want to use it at another place and print out as an image tag.

<?php $tmp_query = new WP_Query('showposts=6');
while ( $tmp_query->have_posts() ) : $tmp_query->the_post();

 <?php endwhile;wp_reset_query(); ?> 
share|improve this question
showposts is deprecated use posts_per_page instead – JMau Aug 27 '13 at 9:18
JMau !!! thanks but my question is not about showposts!! – user35212 Aug 27 '13 at 9:21
downvoted for lack of research: Codex codex.wordpress.org/Function_Reference/get_the_post_thumbnail – Michael Aug 27 '13 at 9:23
Not a good reason for using deprecated code. – JMau Aug 27 '13 at 9:23

Most WordPress functions that echo a result have sister function that return the result. To find them, go to the the Codex reference page for the function you are using. For this function, search Google with this phrase:

site:codex.wordpress.org the_post_thumbnail

Click on the link to the function then on the Related section and you will find other functions related to this one, including a link to the get_the_post_thumbnail() function.

The WordPress community has added most WordPress functions to the Function Reference and to the Template Tags sections of the Codex.

share|improve this answer

With a tiny bit of research, I'm pretty sure you could have created this yourself:

$imageid = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );
$featimage = $imageid['0'];
$printable_url = '<img src="' . $featimage . '">';

echo $printable_url;
share|improve this answer

I too was rather confused by a similar attempt to use the_post_thumbnail() and it's alternate get_the_post_thumbnail(). Patrik's previous answer worked very well for me on that occasion, and I have since had good success with a combination of the two.

I had no luck with:


but rather better success including $post->ID

get_the_post_thumbnail($page->ID, 'thumbnail');

The saddest part is that it is all in the WP codex... I just appear to have forgotten 'how' to read :)

share|improve this answer

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.