Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. $args = array(
  2. 'post_type' => 'auction_dates',
  3. 'paged' => $paged,
  4. 'posts_per_page' => 1,
  5. 'meta_key' => 'date_of_auction',
  6. 'orderby' => 'meta_value_num',
  7. 'order' => 'ASC');
  8.  
  9. $previous_adjacent_post = get_adjacent_post(true,'',true, 'product_cat');
  10. $next_adjacent_post = get_adjacent_post(true,'',false, 'product_cat');
  11.  
  12. if(is_a($previous_adjacent_post, 'WP_Post')){
  13. $previous_link = get_permalink($previous_adjacent_post->ID);
  14. $previous_title = $previous_adjacent_post->post_title;
  15. }
  16. if(is_a($next_adjacent_post, 'WP_Post')){
  17. $next_link = get_permalink($next_adjacent_post->ID);
  18. $next_title = $next_adjacent_post->post_title;
  19. }
  20.  
  21. <?php next_post_link_plus( array('in_same_meta' => 'publisher') ); ?>
  22.  
  23. function get_adjacent_posts($args) {
  24. global $post;
  25.  
  26. $all_posts = get_posts($args);
  27. $len = count($all_posts);
  28. $np = null;
  29. $cp = $post;
  30. $pp = null;
  31.  
  32. if ($len > 1) {
  33. for ($i=0; $i < $len; $i++) {
  34. if ($all_posts[$i]->ID === $cp->ID) {
  35. if (array_key_exists($i-1, $all_posts)) {
  36. $pp = $all_posts[$i-1];
  37. } else {
  38. $new_key = $len-1;
  39. $pp = $all_posts[$new_key];
  40.  
  41. while ($pp->ID === $cp->ID) {
  42. $new_key -= 1;
  43. $pp = $all_posts[$new_key];
  44. }
  45. }
  46.  
  47. if (array_key_exists($i+1, $all_posts)) {
  48. $np = $all_posts[$i+1];
  49. } else {
  50. $new_key = 0;
  51. $np = $all_posts[$new_key];
  52.  
  53. while ($pp->ID === $cp->ID) {
  54. $new_key += 1;
  55. $np = $all_posts[$new_key];
  56. }
  57. }
  58.  
  59. break;
  60. }
  61. }
  62. }
  63.  
  64. return array('next' => $np, 'prev' => $pp);
  65. }
  66.  
  67. $args = array(
  68. 'post_type' => 'custom_post_type',
  69. 'posts_per_page' => -1,
  70. 'order' => 'ASC',
  71. 'orderby' => 'title'
  72. );
  73.  
  74. $adjacent = get_adjacent_posts($args);
  75.  
  76. $next_title = $adjacent['next']->post_title;
  77. $next_image = get_the_post_thumbnail_url($adjacent['next']->ID, 'square');
  78. $next_url = get_permalink($adjacent['next']);
  79.  
  80. $prev_title = $adjacent['prev']->post_title;
  81. $prev_image = get_the_post_thumbnail_url($adjacent['next']->ID, 'square');
  82. $prev_url = get_permalink($adjacent['prev']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement