brian914
Member
Posted 11 months ago #
I am trying to access the image gallery via code. I have looked around a bit, but can't seem to find info on this. I have a loop that goes through my posts and accesses headlines, content, etc. for each one. I now would like to also access images that are attached to those posts. Where can I find info on this topic?
Thanks a lot!
brian914
Member
Posted 11 months ago #
I found what I was looking for in case anyone else is having issue with this down the line. I placed the following inside my loop and am now able to access the info I want.
<?php
$args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID );
$attachments = get_posts($args);
if ($attachments) {
foreach ( $attachments as $attachment ) {
echo apply_filters( 'the_title' , $attachment->post_title );
the_attachment_link( $attachment->ID , false );
}
}
?>