Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php	(revision 18397)
+++ wp-includes/link-template.php	(working copy)
@@ -1104,6 +1104,12 @@
 		return null;
 
 	$current_post_date = $post->post_date;
+	
+	if ( $in_same_cat && taxonomy_exists( $in_same_cat ) ) {
+		$taxonomy = $in_same_cat; 
+	} else {
+		$taxonomy = 'category';
+	}
 
 	$join = '';
 	$posts_in_ex_cats_sql = '';
@@ -1111,11 +1117,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 .= " AND tt.taxonomy = '" . $taxonomy ."' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
 		}
 
-		$posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
+		$posts_in_ex_cats_sql = "AND tt.taxonomy = '" . $taxonomy ."'";
 		if ( !empty($excluded_categories) ) {
 			$excluded_categories = array_map('intval', explode(' and ', $excluded_categories));
 			if ( !empty($cat_array) ) {
@@ -1124,7 +1130,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 = " AND tt.taxonomy = '" . $taxonomy . "' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';
 			}
 		}
 	}
