This method works for WordPress posts as well as custom post types.
Use the following code inside of the WordPress loop to extract the next and previous post links.
...
$pp_url = get_permalink( get_previous_post()->ID );
$np_url = get_permalink( get_next_post()->ID );
...
Code language: PHP (php)
Read more
- WordPress: get_previous_post()
- WordPress: get_next_post()