Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Next Post Mod
- add_filter( 'get_next_post_where', function( $where, $in_same_term, $excluded_terms )
- {
- global $post, $wpdb;
- // Edit this custom post type to your needs
- $cpt = 'post';
- // Current post type
- $post_type = get_post_type( $post );
- // Nothing to do
- if( $in_same_term || ! empty( $excluded_terms ) || $cpt !== $post_type )
- return $where;
- // Next CPT order by last word in title
- add_filter( 'get_next_post_sort', function( $orderby )
- {
- return " ORDER BY p.post_title ASC LIMIT 1 ";
- } );
- // Modify Next WHERE part
- return $wpdb->prepare(
- " WHERE
- p.post_title > '%s'
- AND p.post_type = '%s'
- AND p.post_status = 'publish'
- ",
- $post->post_title,
- $post_type
- );
- }, 10, 3 );
- // Previous Post Mod
- add_filter( 'get_previous_post_where', function( $where, $in_same_term, $excluded_terms)
- {
- global $post, $wpdb;
- // Edit this custom post type to your needs
- $cpt = 'post';
- // Current post type
- $post_type = get_post_type( $post );
- // Nothing to do
- if( $in_same_term || ! empty( $excluded_terms ) || $cpt !== $post_type )
- return $where;
- // Previous CPT, order by last word in post title
- add_filter( 'get_previous_post_sort', function( $orderby )
- {
- return " ORDER BY p.post_title DESC LIMIT 1 ";
- } );
- // Modify Prev WHERE part
- return $wpdb->prepare(
- " WHERE
- p.post_title < '%s'
- AND p.post_type = '%s'
- AND p.post_status = 'publish'
- ",
- $post->post_title,
- $post_type
- );
- }, 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment