Skip to content

Instantly share code, notes, and snippets.

Created June 10, 2016 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/50d27caa1abf9e432bbea5c05ee7dd46 to your computer and use it in GitHub Desktop.
Save anonymous/50d27caa1abf9e432bbea5c05ee7dd46 to your computer and use it in GitHub Desktop.
Filter prev/next post by menu_order on custom post type
function loud_previous_post_where() {
global $post, $wpdb;
if ( 'case_study' == $post->post_type ) {
return $wpdb->prepare( "WHERE p.menu_order < %s AND p.post_type = %s AND p.post_status = 'publish'", $post->menu_order, $post->post_type);
} else {
return $wpdb->prepare("WHERE p.post_date < %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;
}
}
add_filter( 'get_previous_post_where', 'loud_previous_post_where' );
function loud_next_post_where() {
global $post, $wpdb;
if ( 'case_study' == $post->post_type ) {
return $wpdb->prepare( "WHERE p.menu_order > %s AND p.post_type = %s AND p.post_status = 'publish'", $post->menu_order, $post->post_type);
} else {
return $wpdb->prepare("WHERE p.post_date > %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;
}
}
add_filter( 'get_next_post_where', 'loud_next_post_where' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment