Created
June 10, 2016 03:34
-
-
Save anonymous/50d27caa1abf9e432bbea5c05ee7dd46 to your computer and use it in GitHub Desktop.
Filter prev/next post by menu_order on custom post type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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