get_next_post

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

Description

(null|string|WP_Post) get_next_post( (constant) $in_same_term = false, (string) $excluded_terms = '', (string) $taxonomy = 'category' ); 

Returns (null|string|WP_Post)

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

Parameters (3)

0. $in_same_term — Optional. (constant) => false
Whether post should be in a same taxonomy term. Default false.
1. $excluded_terms — Optional. (string) => ''
Array or comma-separated list of excluded term IDs. Default empty.
2. $taxonomy — Optional. (string) => 'category'
Taxonomy, if $in_same_term is true. Default category..

Usage

  1. if ( !function_exists( 'get_next_post' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // Optional. Whether post should be in a same taxonomy term. Default false. 
  5. $in_same_term = false; 
  6.  
  7. // Optional. Array or comma-separated list of excluded term IDs. Default empty. 
  8. $excluded_terms = ''; 
  9.  
  10. // Optional. Taxonomy, if $in_same_term is true. Default 'category'. 
  11. $taxonomy = 'category'; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = get_next_post($in_same_term, $excluded_terms, $taxonomy); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/link-template.php  
  1. function get_next_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { 
  2. return get_adjacent_post( $in_same_term, $excluded_terms, false, $taxonomy );