Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php	(revision 17159)
+++ wp-includes/link-template.php	(working copy)
@@ -1095,10 +1095,10 @@
  * @param bool $previous Optional. Whether to retrieve previous post.
  * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.
  */
-function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) {
+function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'post') {
 	global $post, $wpdb;
 
-	if ( empty( $post ) )
+	if ( empty( $post ) || !taxonomy_exists( $taxonomy ) )
 		return null;
 
 	$current_post_date = $post->post_date;
@@ -1109,11 +1109,11 @@
 		$join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
 
 		if ( $in_same_cat ) {
-			$cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids'));
-			$join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
+			$cat_array = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids'));
+			$join .= $wpdb->prepare(" AND tt.taxonomy = '%s' AND tt.term_id IN (" . implode(',', $cat_array) . ")", $taxonomy);
 		}
 
-		$posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
+		$posts_in_ex_cats_sql = $wpdb->prepare("AND tt.taxonomy = '%s'", $taxonomy);
 		if ( !empty($excluded_categories) ) {
 			$excluded_categories = array_map('intval', explode(' and ', $excluded_categories));
 			if ( !empty($cat_array) ) {
@@ -1122,7 +1122,7 @@
 			}
 
 			if ( !empty($excluded_categories) ) {
-				$posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';
+				$posts_in_ex_cats_sql = $wpdb->prepare(" AND tt.taxonomy = '%s' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')', $taxonomy);
 			}
 		}
 	}
@@ -1131,12 +1131,12 @@
 	$op = $previous ? '<' : '>';
 	$order = $previous ? 'DESC' : 'ASC';
 
-	$join  = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories );
-	$where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date, $post->post_type), $in_same_cat, $excluded_categories );
-	$sort  = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
+	$join  = apply_filters( "get_{$adjacent}_{$taxonomy}_join", $join, $in_same_cat, $excluded_categories );
+	$where = apply_filters( "get_{$adjacent}_{$taxonomy}_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date, $post->post_type), $in_same_cat, $excluded_categories );
+	$sort  = apply_filters( "get_{$adjacent}_{$taxonomy}_sort", "ORDER BY p.post_date $order LIMIT 1" );
 
 	$query = "SELECT p.* FROM $wpdb->posts AS p $join $where $sort";
-	$query_key = 'adjacent_post_' . md5($query);
+	$query_key = "adjacent_{$taxonomy}_" . md5($query);
 	$result = wp_cache_get($query_key, 'counts');
 	if ( false !== $result )
 		return $result;
