WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Scribu's Posts 2 Posts plugin to connect posts with small galleries attached to an album post type. Everything works great, except that I cannot figure out how to merge the attachments to display together.

Right now I am using the code below to display each gallery one below another.

$images = get_children( array( 
    'post_parent' => $post->ID,
    'post_type' => 'attachment',
    'post_mime_type' => 'image', 
    'orderby' => 'menu_order',
    'order' => 'ASC',
    'numberposts' => 999 ) );

if ( $images ) {
    $total_images = count( $images );
    $image = array_shift( $images );
    $image_img_tag = wp_get_attachment_image( $image->ID, 'thumbnail', $default_attr );

if ($images)
    echo do_shortcode('[gallery size="small" columns="5"]');

Is it possible to grab all of the post attachments connect to an album and combine before this script is run?

share|improve this question
up vote 1 down vote accepted

You will just have to call get_children() for each gallery:

$images = array();

foreach ( $gallery_posts as $gallery ) {
  $images = array_merge( $images, get_children(
    'post_parent' => $gallery->ID,
  ) );
share|improve this answer
Awesome thanks @Scribu! – mattrepublic Oct 19 '11 at 11:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.