Skip to content

Instantly share code, notes, and snippets.

/functions.php
Created Jun 10, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.