get_adjacent_post – A WordPress function to retrieve previous or next post. It is mostly useful if you want to integrate go to next/previous post button in your WordPress theme.


$in_same_cat(optional)(boolean) – If you want to retrieve next/previous post from same category

$excluded_categories (optional)(string) – String of comma-separated category ids

$previous(optional)(boolean) – If you want to retrieve previous post

Basic usage examples:

$previousPost = get_adjacent_post(true, "", true));
$nextPost = get_adjacent_post(true);

<?php if($previousPost) : ?>
    <a href="<?php echo get_permalink($previousPost->ID)?>">&laquo; Previous post</a>
<?php endif; ?>

<?php if($nextPost) : ?>
    <a href="<?php echo get_permalink($nextPost->ID)?>">Next: <?php echo $next->post_title; ?> &raquo;</a>
<?php endif; ?>