query attachments of parent page if attachments of current page are smaller than …

I’m not quite sure how you’re defining whether or not the current page has only “small” images. But I suspect the answer is right in the wp_get_attachment_image_src function, which returns not just the image url but also the width and height.

So let’s say you were only interested in images that are more than 300 pixels wide. First, add this to your functions.php file:

function return_my_big_images( $id ) {

    $query_images_args = array(
        'post_type' => 'attachment',
        'post_mime_type' => 'image',
        'post_status' => 'inherit',
        'posts_per_page' => -1,
        'post_parent' => $id

    $attachments = get_children( $query_images_args );

    $big_images = array();
    foreach( $attachments as $image ) {
        $image_src = wp_get_attachment_image_src( $image->ID, 'full' );
        if ( $image_src[1] > 300 ) // $image_src[1] is where pixel width is stored
            $big_images[] = $image_src[0]; // $image_src[0] is its url

    return $big_images;


Then, instead of your code above, you can add this:

global $post;

// return all images bigger than 300px wide attached to current post
$big_images = return_my_big_images( $post->ID );

// if none, return images bigger than 300px wide attached to post parent
if ( empty( $big_images ) )
    $big_images = return_my_big_images( $post->post_parent );