Support » Themes and Templates » Image Gallery access via API?

  • Resolved brian914

    (@brian914)


    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!

Viewing 1 replies (of 1 total)
  • brian914

    (@brian914)

    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 );
    	}
    }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Image Gallery access via API?’ is closed to new replies.