get_next_post()WP 1.5.0

Retrieves the next post (as object) from the specified taxonomy (the default is category).

To get a link to the previous post, use get_previous_post().

1 time — 0.00286 sec (very slow) | 50000 times — 1.85 sec (fast) | PHP 7.1.5, WP 4.8.1

No Hooks.


WP_Post|null|String. Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists.


get_next_post( $in_same_term, $excluded_terms, $taxonomy );
Whether post should be in the same taxonomy term.
Default: false
Array or comma-separated list of excluded term IDs.
Default: ''
Taxonomy, if $in_same_term is true.
Default: 'category'



#1 Display the next post

Next post in relation to the previous one will be shown, if such a post exists:

$next_post = get_next_post();

if( ! empty( $next_post ) ){
	<a href="<?php echo get_permalink( $next_post->ID ); ?>">
		<?php echo $next_post->post_title; ?>


Since 1.5.0 Introduced.

get_next_post() code WP 6.5.2

function get_next_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
	return get_adjacent_post( $in_same_term, $excluded_terms, false, $taxonomy );