[resolved] Image Gallery access via API? (2 posts)

  1. brian914
    Posted 5 years 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!

  2. brian914
    Posted 5 years 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.

    $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 );

Topic Closed

This topic has been closed to new replies.

About this Topic