Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php	(revision 18646)
+++ wp-includes/link-template.php	(working copy)
@@ -1066,10 +1066,11 @@
  *
  * @param bool $in_same_cat Optional. Whether post should be in same category.
  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
+ * @param string $taxonomy Optional. Which taxonomy to use.
  * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.
  */
-function get_previous_post($in_same_cat = false, $excluded_categories = '') {
-	return get_adjacent_post($in_same_cat, $excluded_categories);
+function get_previous_post($in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') {
+	return get_adjacent_post($in_same_cat, $excluded_categories, true, $taxonomy);
 }
 
 /**
@@ -1079,10 +1080,11 @@
  *
  * @param bool $in_same_cat Optional. Whether post should be in same category.
  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
+ * @param string $taxonomy Optional. Which taxonomy to use.
  * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.
  */
-function get_next_post($in_same_cat = false, $excluded_categories = '') {
-	return get_adjacent_post($in_same_cat, $excluded_categories, false);
+function get_next_post($in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') {
+	return get_adjacent_post($in_same_cat, $excluded_categories, false, $taxonomy);
 }
 
 /**
@@ -1095,12 +1097,13 @@
  * @param bool $in_same_cat Optional. Whether post should be in same category.
  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
  * @param bool $previous Optional. Whether to retrieve previous post.
+ * @param string $taxonomy Optional. Which taxonomy to use.
  * @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 = 'category' ) {
 	global $post, $wpdb;
 
-	if ( empty( $post ) )
+	if ( empty( $post ) || ! taxonomy_exists( $taxonomy ) )
 		return null;
 
 	$current_post_date = $post->post_date;
@@ -1111,11 +1114,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 (%s)", $taxonomy, implode(',', $cat_array) );
 		}
 
-		$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 ) ) {
 			if ( ! is_array( $excluded_categories ) ) {
 				// back-compat, $excluded_categories used to be IDs separated by " and "
@@ -1135,7 +1138,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 (%s)", $taxonomy, implode(',', $excluded_categories) );
 			}
 		}
 	}
@@ -1173,13 +1176,14 @@
  * @param bool $in_same_cat Optional. Whether link should be in same category.
  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
  * @param bool $previous Optional, default is true. Whether display link to previous post.
+ * @param string $taxonomy Optional. Which taxonomy to use.
  * @return string
  */
-function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) {
+function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'category') {
 	if ( $previous && is_attachment() && is_object( $GLOBALS['post'] ) )
 		$post = & get_post($GLOBALS['post']->post_parent);
 	else
-		$post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);
+		$post = get_adjacent_post( $in_same_cat, $excluded_categories, $previous, $taxonomy );
 
 	if ( empty($post) )
 		return;
@@ -1209,10 +1213,11 @@
  * @param string $title Optional. Link title format.
  * @param bool $in_same_cat Optional. Whether link should be in same category.
  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
+ * @param string $taxonomy Optional. Which taxonomy to use.
  */
-function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
-	echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true);
-	echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false);
+function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') {
+	echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true, $taxonomy);
+	echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false, $taxonomy);
 }
 
 /**
@@ -1236,9 +1241,10 @@
  * @param string $title Optional. Link title format.
  * @param bool $in_same_cat Optional. Whether link should be in same category.
  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
+ * @param string $taxonomy Optional. Which taxonomy to use.
  */
-function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
-	echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false);
+function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') {
+	echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false, $taxonomy);
 }
 
 /**
@@ -1249,9 +1255,10 @@
  * @param string $title Optional. Link title format.
  * @param bool $in_same_cat Optional. Whether link should be in same category.
  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
+ * @param string $taxonomy Optional. Which taxonomy to use.
  */
-function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
-	echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true);
+function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') {
+	echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true, $taxonomy);
 }
 
 /**
@@ -1265,9 +1272,10 @@
  * @param bool $in_same_cat Optional. Whether returned post should be in same category.
  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
  * @param bool $start Optional. Whether to retrieve first or last post.
+ * @param string $taxonomy Optional. Which taxonomy to use.
  * @return object
  */
-function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $start = true ) {
+function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $start = true, $taxonomy = 'category' ) {
 	global $post;
 
 	if ( empty($post) || ! is_single() || is_attachment() )
@@ -1279,7 +1287,7 @@
 		
 	if ( $in_same_cat || ! empty( $excluded_categories ) ) {
 		if ( $in_same_cat )
-			$cat_array = wp_get_object_terms( $post->ID, 'category', array( 'fields' => 'ids' ) );
+			$cat_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
 
 		if ( ! empty( $excluded_categories ) ) {
 			$excluded_categories = array_map( 'intval', $excluded_categories );
@@ -1295,8 +1303,23 @@
 	$categories = implode( ',', array_merge( $cat_array, $excluded_categories ) );
 
 	$order = $start ? 'ASC' : 'DESC';
+	
+	$args = array(
+		'posts_per_page' => '1',
+		'order' => $order,
+		'update_post_term_cache' => false,
+		'update_post_meta_cache' => false,
+		'tax_query' => array(
+			array(
+				'taxonomy' => $taxonomy,
+				'field' => 'id',
+				'terms' => $categories
+			)
+		)
+		
+	);
 
-	return get_posts( array('numberposts' => 1, 'category' => $categories, 'order' => $order, 'update_post_term_cache' => false, 'update_post_meta_cache' => false) );
+	return get_posts( $args );
 }
 
 /**
@@ -1310,10 +1333,11 @@
  * @param bool $in_same_cat Optional. Whether link should be in same category.
  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
  * @param bool $start Optional, default is true. Whether display link to first or last post.
+ * @param string $taxonomy Optional. Which taxonomy to use.
  * @return string
  */
-function get_boundary_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $start = true) {
-	$posts = get_boundary_post($in_same_cat, $excluded_categories, $start);
+function get_boundary_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $start = true, $taxonomy = 'category') {
+	$posts = get_boundary_post($in_same_cat, $excluded_categories, $start, $taxonomy);
 	// If there is no post stop.
 	if ( empty($posts) )
 		return;
@@ -1346,9 +1370,10 @@
  * @param string $title Optional. Link title format.
  * @param bool $in_same_cat Optional. Whether link should be in same category.
  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
+ * @param string $taxonomy Optional. Which taxonomy to use.
  */
-function start_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') {
-	echo get_boundary_post_rel_link($title, $in_same_cat, $excluded_categories, true);
+function start_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') {
+	echo get_boundary_post_rel_link($title, $in_same_cat, $excluded_categories, true, $taxonomy);
 }
 
 /**
@@ -1418,9 +1443,10 @@
  * @param string $link Optional. Link permalink format.
  * @param bool $in_same_cat Optional. Whether link should be in same category.
  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
+ * @param string $taxonomy Optional. Which taxonomy to use.
  */
-function previous_post_link($format='&laquo; %link', $link='%title', $in_same_cat = false, $excluded_categories = '') {
-	adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true);
+function previous_post_link($format='&laquo; %link', $link='%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') {
+	adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true, $taxonomy);
 }
 
 /**
@@ -1432,9 +1458,10 @@
  * @param string $link Optional. Link permalink format.
  * @param bool $in_same_cat Optional. Whether link should be in same category.
  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
+ * @param string $taxonomy Optional. Which taxonomy to use.
  */
-function next_post_link($format='%link &raquo;', $link='%title', $in_same_cat = false, $excluded_categories = '') {
-	adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
+function next_post_link($format='%link &raquo;', $link='%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') {
+	adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false, $taxonomy);
 }
 
 /**
@@ -1449,12 +1476,13 @@
  * @param bool $in_same_cat Optional. Whether link should be in same category.
  * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs.
  * @param bool $previous Optional, default is true. Whether display link to previous post.
+ * @param string $taxonomy Optional. Which taxonomy to use.
  */
-function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {
+function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'category') {
 	if ( $previous && is_attachment() )
 		$post = & get_post($GLOBALS['post']->post_parent);
 	else
-		$post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
+		$post = get_adjacent_post($in_same_cat, $excluded_categories, $previous, $taxonomy);
 
 	if ( !$post )
 		return;
