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 want use these code to load src of images that attachs in wordpress's post:

$recent = new WP_Query("showposts=30"); while($recent->have_posts()) : $recent->the_post();

        $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array(80,80) );
        echo $thumb[0];


but my code don't work, and give me nothing.

please help me

share|improve this question

The following line is incorrect as showposts is deprecated.

$recent = new WP_Query("showposts=30");

Instead use,

$recent = new WP_Query('posts_per_page=30');

Following that,

Does the thumbnail size of 80x80 exist?


If not try any of,

$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), small );
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), medium );
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), large );

Remember each of small, medium or large - refers to different filenames or src - so if you want to retrieve the full resolution image, original upload then use large.

If you must return the src URL as

http://domain.com/image_80x_80x.jpg //example

...meaning that you definitely want the 80x80 version and it does not exist then you will need to regenerate your thumbnails.

You can use: http://wordpress.org/extend/plugins/regenerate-thumbnails/

If you did not add the image size of 80x80 to your theme you can do so using the add_image_size function in your functions.php file,

add_image_size( 'my_custom_size', 80, 80 );

Now, when uploading new images, you will also get a 80x80 version. You can then refer to it as mentioned above by either,

wp_get_attachment_image_src( $id, array(80,80) ); //via array specifying pixel w & h


wp_get_attachment_image_src( $id, my_custom_size ); //via name used in add_image_size
share|improve this answer
thanks but new code don't work – Ehsan Sep 20 '12 at 7:06

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.