get_adjacent_post() uses the global $post as its reference point, so you will want to replace this:
$this_post = get_post($post_id);
with this:
global $post; $post = get_post($post_id);
WordPress also provides get_next_post() and get_previous_post() , which you can use here instead of using get_adjacent_post() with all of these arguments. Here is the final product:
<?php require_once("../../../wp-blog-header.php"); if (isset($_POST['data'])){ $post_id = $_POST['data']; }else{ $post_id = ""; } $wp_query->is_single = true; global $post; $post = get_post($post_id); $previous_post = get_previous_post(); $next_post = get_next_post(); $post_id = $next_post->id; $title = $next_post->post_title; $dataset = array ( "postid"=>$post_id, "posttitle"=>$title );
I'm not sure which keys you would like to use for the identifiers and headers of the previous and next messages in the $dataset , so I will leave this as it is for now.
source share