Get previous and next post title and content wordpress

by Expert of Tech

I have got an issue creating and previous and next post navigation for the WordPress website. then I got this.

function get_previous_post_id( $post_id ) {
  // Get a global post reference since get_adjacent_post() references it
  global $post;

  // Store the existing post object for later so we don't lose it
  $oldGlobal = $post;

  // Get the post object for the specified post and place it in the global variable
  $post = get_post( $post_id );

  // Get the post object for the previous post
  $previous_post = get_previous_post();

  // Reset our global object
  $post = $oldGlobal;

  if ( '' == $previous_post ) {
      return 0;

  return $previous_post->ID;

// pass current post id;
get_previous_post_id( $current_post_id );