Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. // get_posts in same custom taxonomy
  2. $postlist_args = array(
  3. 'posts_per_page' => -1,
  4. 'orderby' => 'menu_order title',
  5. 'order' => 'ASC',
  6. 'post_type' => 'lessons',
  7. 'your_custom_taxonomy' => 'curs'
  8. );
  9. $postlist = get_posts( $postlist_args );
  10.  
  11. // get ids of posts retrieved from get_posts
  12. $ids = array();
  13. foreach ($postlist as $thepost) {
  14. $ids[] = $thepost->ID;
  15. }
  16.  
  17. // get and echo previous and next post in the same taxonomy
  18. $thisindex = array_search($post->ID, $ids);
  19. $previd = $ids[$thisindex-1];
  20. $nextid = $ids[$thisindex+1];
  21. if ( isset($previd) ) {
  22. echo '<a rel="prev" href="' . get_permalink($previd). '">previous</a>';
  23. }
  24. if ( isset($nextid) ) {
  25. echo '<a rel="next" href="' . get_permalink($nextid). '">next</a>';
  26. }
  27. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement