Skip to content

Instantly share code, notes, and snippets.

@seafarer
Created July 24, 2013 03:22
Show Gist options
  • Select an option

  • Save seafarer/6067849 to your computer and use it in GitHub Desktop.

Select an option

Save seafarer/6067849 to your computer and use it in GitHub Desktop.
Access wordpress post images uploaded and inserted through gallery function
<?php
$args = array(
'numberposts' => -1, // Using -1 loads all posts
'orderby' => 'menu_order', // This ensures images are in the order set in the page media manager
'order'=> 'ASC',
'post_mime_type' => 'image', // Make sure it doesn't pull other resources, like videos
'post_parent' => $post->ID, // Important part - ensures the associated images are loaded
'post_status' => null,
'post_type' => 'attachment'
);
$images = get_children( $args );
if($images){ ?>
<div id="slider">
<?php foreach($images as $image){ ?>
<img src="<?php echo $image->guid; ?>" alt="<?php echo $image->post_title; ?>" title="<?php echo $image->post_title; ?>" />
<?php } ?>
</div>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment