Skip to content

Instantly share code, notes, and snippets.

@resarahman
Created November 3, 2015 10:25
Show Gist options
  • Save resarahman/a7cae9a3d4ba6bfc637d to your computer and use it in GitHub Desktop.
Save resarahman/a7cae9a3d4ba6bfc637d to your computer and use it in GitHub Desktop.
Next/Prev post link based on meta_key value
<?php
function custom_next_prev_post_links( $join, $in_same_term, $excluded_terms, $taxonomy, $post ){
global $wpdb;
$join .= " INNER JOIN $wpdb->postmeta AS m ON p.ID = m.post_id AND m.meta_key = 'your_meta_key_name'";
return $join;
}
add_filter('get_next_post_join', 'custom_next_prev_post_links', 10, 5);
add_filter('get_previous_post_join', 'custom_next_prev_post_links', 10, 5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment