title: Getting Next/Previous Post ID using Current Post ID in Wordpress
body: <p>I want to write a custom next/prev function to dynamically display post information in a fancybox pop-up. So I need to use PHP to get the next and previous Post ID based on whatever Post is currently showing. I know what the current post ID is and I can send that to a function ok, but I can't figure out how to use that ID to obtain the adjacent IDs.</p>
  
  <p>Edit:Here is my code so far (which is not working)</p>
  
  <pre><code>&lt;?php
  require_once("../../../wp-blog-header.php");
  
  if (isset($_POST['data'])){
      $post_id = $_POST['data'];
  }else{
      $post_id = "";
  }
  $wp_query-&gt;is_single = true;
  $this_post = get_post($post_id);
  $in_same_cat = false;
  $excluded_categories = '';
  $previous = false;
  $next_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);
  
  
  $post_id = $next_post-&gt;id;
  $title = $next_post-&gt;post_title;
  
  $dataset = array ( "postid"=&gt;$post_id, "posttitle"=&gt;$title );
  
  //Because we want to use json, we have to place things in an array and encode it for json.
  //This will give us a nice javascript object on the front side.
  
  echo json_encode($dataset);
  
  
  ?&gt;
  </code></pre>