Guest User

Untitled

a guest
Aug 29th, 2016
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. function get_pagination_in_json( $post_response, $post, $context ) {
  2.  
  3. // Ensure global post is correctly set
  4. $old_post = $GLOBALS['post'];
  5. $GLOBALS['post'] = (object)$post;
  6.  
  7. $previous_post = get_adjacent_post( true, '', true, 'my_custom_taxonomy_name' );
  8. $next_post = get_adjacent_post( true, '', false, 'my_custom_taxonomy_name' );
  9.  
  10. if ( is_a( $previous_post, 'WP_Post' ) ) {
  11. $previous = get_permalink($previous_post->ID);
  12. $post_response['pagination']['previous'] = $previous;
  13. }
  14.  
  15. if ( is_a( $next_post, 'WP_Post' ) ) {
  16. $next = get_permalink($next_post->ID);
  17. $post_response['pagination']['next'] = $next;
  18. }
  19.  
  20. // Reset global post to its old value
  21. $GLOBALS['post'] = $old_post;
  22.  
  23. return $post_response;
  24. }
  25. add_filter( 'json_prepare_post', 'get_pagination_in_json', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment