Post images not displaying as attachments

Question

I am trying to display the images attached to a post in single.php I’ve used :

<?php if (have_posts()) : while(have_posts()) : the_post(); ?>

$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => 'any',
'post_parent' => $post->ID
);


$attachments = get_posts($args);

if ($attachments) : ?>
    <ul class="portfolio-image-list">

    <?php foreach($attachments as $attachment): ?>
        <li class="box">
        <figure>
        <?php the_attachment_link($attachment->ID, true); ?>
            <figcaption><?php echo $attachment->post_title; ?></figcaption>
        </figure>
    </li>
    <?php endforeach; ?>
    </ul>
    <?php else : ?>

            <p>No images found for this post.</p>

<?php endif; ?>

 <?php endwhile; ?>
 <?php endif; ?>

However, the image seems to be in the post content (as confirmed by var_dump($post) and there are no attachments var_dump($attachments) gives me an empty array.

I seem to be misunderstanding something here…

var_dump($post); gives me :

 object(WP_Post)#136 (25) { 
 ["ID"]=> int(91) 
 ["post_author"]=> string(1) "1" 
 ["post_date"]=> string(19) "2013-09-04 13:14:17" 
 ["post_date_gmt"]=> string(19) "2013-09-04 13:14:17" 
 ["post_content"]=> string(285) "Snowy Egret"
 ["post_title"]=> string(11) "Snowy Egret"
 ["post_excerpt"]=> string(0) ""
 ["post_status"]=> string(7) "publish"
 ["comment_status"]=> string(4) "open"
 ["ping_status"]=> string(4) "open"
 ["post_password"]=> string(0) ""
 ["post_name"]=> string(11) "snowy-egret"
 ["to_ping"]=> string(0) ""
 ["pinged"]=> string(0) ""
 ["post_modified"]=> string(19) "2013-09-06 08:36:01"
 ["post_modified_gmt"]=> string(19) "2013-09-06 08:36:01      
 ["post_content_filtered"]=> string(0) ""
 ["post_parent"]=> int(0)
 ["guid"]=> string(44) "/trouble_focusing/?p=91" 
 ["menu_order"]=> int(0)
 ["post_type"]=> string(4) "post"
 ["post_mime_type"]=> string(0) ""
 ["comment_count"]=> string(1) "0"
 ["filter"]=> string(3) "raw"
 ["format_content"]=> NULL
}
0
mantis 6 months 0 Answers 69 views 0

Leave an answer