Index: wp-includes/media.php
===================================================================
--- wp-includes/media.php	(revision 39527)
+++ wp-includes/media.php	(working copy)
@@ -2673,6 +2673,9 @@
  *
  * @since 2.5.0
  *
+ * @uses _previous_image_post_where_filter_once()
+ * @uses _next_image_post_where_filter_once()
+ *
  * @param bool         $prev Optional. Whether to display the next (false) or previous (true) link. Default true.
  * @param string|array $size Optional. Image size. Accepts any valid image size, or an array of width and height
  *                           values in pixels (in that order). Default 'thumbnail'.
@@ -2679,29 +2682,30 @@
  * @param bool         $text Optional. Link text. Default false.
  */
 function adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) {
+	$adjacent = $prev ? 'previous' : 'next';
+	$order = $prev ? 'DESC' : 'ASC';
 	$post = get_post();
-	$attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) );
 
-	foreach ( $attachments as $k => $attachment ) {
-		if ( $attachment->ID == $post->ID ) {
-			break;
-		}
-	}
+	add_filter( 'posts_where', "_{$adjacent}_image_posts_where_filter_once" );
 
+	$attachment = array_pop( get_children( array( 
+		'post_parent'      => $post->post_parent, 
+		'post_status'      => 'inherit', 
+		'post_type'        => 'attachment', 
+		'post_mime_type'   => 'image', 
+		'orderby'          => "menu_order $order, ID $order", 
+		'posts_per_page'   => 1, 
+		'suppress_filters' => false, 
+	) ) );
+
 	$output = '';
 	$attachment_id = 0;
 
-	if ( $attachments ) {
-		$k = $prev ? $k - 1 : $k + 1;
-
-		if ( isset( $attachments[ $k ] ) ) {
-			$attachment_id = $attachments[ $k ]->ID;
-			$output = wp_get_attachment_link( $attachment_id, $size, true, false, $text );
-		}
+	if ( $attachment ) {
+		$attachment_id = $attachment->ID;
+		$output = wp_get_attachment_link( $attachment_id, $size, true, false, $text );
 	}
 
-	$adjacent = $prev ? 'previous' : 'next';
-
 	/**
 	 * Filters the adjacent image link.
 	 *
@@ -2718,6 +2722,24 @@
 	echo apply_filters( "{$adjacent}_image_link", $output, $attachment_id, $size, $text );
 }
 
+/** 
+ * Append to WHERE clause for selecting only the previous image. 
+ */ 
+function _previous_image_posts_where_filter_once( $where ) { 
+	remove_filter( 'posts_where', __FUNCTION__ ); 
+	$post = get_post(); 
+	return "$where AND (menu_order < $post->menu_order OR (menu_order = $post->menu_order AND ID < $post->ID))"; 
+} 
+
+/** 
+ * Append to WHERE clause for selecting only the next image. 
+ */ 
+function _next_image_posts_where_filter_once( $where ) { 
+	remove_filter( 'posts_where', __FUNCTION__ ); 
+	$post = get_post(); 
+	return "$where AND (menu_order > $post->menu_order OR (menu_order = $post->menu_order AND ID > $post->ID))"; 
+} 
+
 /**
  * Retrieves taxonomies attached to given the attachment.
  *
