On single.php theme template file, I'm displaying the post's list of attachments.

global $post;
$args = array(
    'post_type' => 'attachment',
    'numberposts' => null,
    'post_status' => null,
    'post_parent' => $o_ID
$attachments = get_posts($args);
if ($attachments) {
    echo '<ul class="slideshow-controller">';
    foreach ($attachments as $attachment) {
        //echo apply_filters('the_title', $attachment->post_title);
        echo '<li>';
        echo wp_get_attachment_link($attachment->ID, 'thumbnail', 0, 0, 'Download');
        echo wp_get_attachment_image($attachment->ID, 'thumbnail',false);
        echo '</li>';
    echo '</ul>';

Weird, wp_get_attachment_linkworks correctly (echoes the attachment's media link), wp_get_attachment_imagedoes not: it echoes nothing at all.

What am i doing wrong?

  • where and how is $oID defined? – iEmanuele Aug 28 '13 at 11:47
  • Just try removing 'numberposts' => null parameter from get_posts() function array $args – Vinod Dalvi Aug 28 '13 at 12:35

Replace the line

echo wp_get_attachment_image($attachment->ID, 'thumbnail',false);


echo $attachments['post_content'];
  • 1
    Thank you, but that does not solve the issue: false refers to the use of the media icon, which is false by default. – pixeline Aug 28 '13 at 11:25
  • I have edited my answer, please try the above code. – user930026 Aug 28 '13 at 11:39
  • $attachments is an array. – s_ha_dum Aug 28 '13 at 11:58

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.