Title: Next / Previous Post Link PHP Error
Last modified: August 20, 2016

---

# Next / Previous Post Link PHP Error

 *  Resolved [Adam](https://wordpress.org/support/users/panhead/)
 * (@panhead)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/next-post-link-php-error/)
 * I’m trying to get the [next_post_link](http://codex.wordpress.org/Function_Reference/next_post_link)
   to work with a custom post type single.php page.
 * My code is:
 *     ```
       <?php next_post_link('%link'); ?>
       <?php previous_post_link('%link'); ?>
       ```
   
 * For some reason, I keep getting this error message along with my links (which,
   strangely enough, do link properly).
 * > Warning: call_user_func_array(): First argument is expected to be a valid callback,‘
   > get_custom_adjacent_post_join’ was given in /wp-includes/plugin.php on line
   > 173
 * This is different from the next_posts_link (posts with an “s”). Any thoughts?

Viewing 1 replies (of 1 total)

 *  Thread Starter [Adam](https://wordpress.org/support/users/panhead/)
 * (@panhead)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/next-post-link-php-error/#post-3357273)
 * I guess I’ll answer my own question again. For anyone’s future reference on how
   to get next_post_link to work with custom post types, just stick this in the 
   theme’s functions.php file:
 *     ```
       <?php
       	function get_custom_adjacent_post_join($join, $in_same_cat) {
       		global $post, $wpdb;
   
       		// we don't process empty post and default post types
       		if (empty($post) || in_array($post->post_type, array('post', 'page', 'attachment', 'revision', 'nav_menu_item')))
       			return $join;
   
       		// here we specify custom post types and their corresponding taxonomies
       		$taxonomies = array(
       			'your_custom_post_type'	=> 'your_taxonomy'
       		);
   
       		$current_taxonomy = $taxonomies[$post->post_type];
   
       		if ($in_same_cat) {
       		$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, $current_taxonomy, array('fields' => 'ids'));
       			$join .= " AND tt.taxonomy = '$current_taxonomy' AND tt.term_id IN (" . implode(',', $cat_array) . ")";
       		}
       		}
       		return $join;
       	}
       	add_filter('get_previous_post_join', 'get_custom_adjacent_post_join', 10, 2);
       	add_filter('get_next_post_join', 'get_custom_adjacent_post_join', 10, 2);
       	?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Next / Previous Post Link PHP Error’ is closed to new replies.

## Tags

 * [custom post type pagination](https://wordpress.org/support/topic-tag/custom-post-type-pagination/)
 * [next post link](https://wordpress.org/support/topic-tag/next-post-link/)
 * [php-error](https://wordpress.org/support/topic-tag/php-error/)
 * [previous post link](https://wordpress.org/support/topic-tag/previous-post-link/)
 * [wp-includes](https://wordpress.org/support/topic-tag/wp-includes/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [Adam](https://wordpress.org/support/users/panhead/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/next-post-link-php-error/#post-3357273)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
