WordPress at Your Fingertips

get_next_post() WP 1.5.0

Retrieves the next post that is adjacent to the current post. Return post object.

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 a 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; ?></a>


Since 1.5.0 Introduced.

Code of get_next_post() WP 5.9

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

Relations (of posts terms...)


vladlu 100vlad.lu
Editors: Kama 101
No comments
    Log In