Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_pagination_in_json( $post_response, $post, $context ) {
- // Ensure global post is correctly set
- $old_post = $GLOBALS['post'];
- $GLOBALS['post'] = (object)$post;
- $previous_post = get_adjacent_post( true, '', true, 'my_custom_taxonomy_name' );
- $next_post = get_adjacent_post( true, '', false, 'my_custom_taxonomy_name' );
- if ( is_a( $previous_post, 'WP_Post' ) ) {
- $previous = get_permalink($previous_post->ID);
- $post_response['pagination']['previous'] = $previous;
- }
- if ( is_a( $next_post, 'WP_Post' ) ) {
- $next = get_permalink($next_post->ID);
- $post_response['pagination']['next'] = $next;
- }
- // Reset global post to its old value
- $GLOBALS['post'] = $old_post;
- return $post_response;
- }
- add_filter( 'json_prepare_post', 'get_pagination_in_json', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment