Guest User

Untitled

a guest
Mar 10th, 2022
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. // Next Post Mod
  2. add_filter( 'get_next_post_where', function( $where, $in_same_term, $excluded_terms )
  3. {
  4. global $post, $wpdb;
  5.  
  6. // Edit this custom post type to your needs
  7. $cpt = 'post';
  8.  
  9. // Current post type
  10. $post_type = get_post_type( $post );
  11.  
  12. // Nothing to do
  13. if( $in_same_term || ! empty( $excluded_terms ) || $cpt !== $post_type )
  14. return $where;
  15.  
  16. // Next CPT order by last word in title
  17. add_filter( 'get_next_post_sort', function( $orderby )
  18. {
  19. return " ORDER BY p.post_title ASC LIMIT 1 ";
  20. } );
  21.  
  22. // Modify Next WHERE part
  23. return $wpdb->prepare(
  24. " WHERE
  25. p.post_title > '%s'
  26. AND p.post_type = '%s'
  27. AND p.post_status = 'publish'
  28. ",
  29. $post->post_title,
  30. $post_type
  31. );
  32.  
  33. }, 10, 3 );
  34.  
  35.  
  36. // Previous Post Mod
  37. add_filter( 'get_previous_post_where', function( $where, $in_same_term, $excluded_terms)
  38. {
  39. global $post, $wpdb;
  40.  
  41. // Edit this custom post type to your needs
  42. $cpt = 'post';
  43.  
  44. // Current post type
  45. $post_type = get_post_type( $post );
  46.  
  47. // Nothing to do
  48. if( $in_same_term || ! empty( $excluded_terms ) || $cpt !== $post_type )
  49. return $where;
  50.  
  51. // Previous CPT, order by last word in post title
  52. add_filter( 'get_previous_post_sort', function( $orderby )
  53. {
  54. return " ORDER BY p.post_title DESC LIMIT 1 ";
  55. } );
  56.  
  57. // Modify Prev WHERE part
  58. return $wpdb->prepare(
  59. " WHERE
  60. p.post_title < '%s'
  61. AND p.post_type = '%s'
  62. AND p.post_status = 'publish'
  63. ",
  64. $post->post_title,
  65. $post_type
  66. );
  67.  
  68. }, 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment