get_previous_post
Retrieves the previous post that is adjacent to the current post.
Description
(null|string|WP_Post) get_previous_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
if ( !function_exists( 'get_previous_post' ) ) { require_once ABSPATH . WPINC . '/link-template.php'; } // Optional. Whether post should be in a same taxonomy term. Default false. $in_same_term = false; // Optional. Array or comma-separated list of excluded term IDs. Default empty. $excluded_terms = ''; // Optional. Taxonomy, if $in_same_term is true. Default 'category'. $taxonomy = 'category'; // NOTICE! Understand what this does before running. $result = get_previous_post($in_same_term, $excluded_terms, $taxonomy);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/link-template.php
- function get_previous_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
- return get_adjacent_post( $in_same_term, $excluded_terms, true, $taxonomy );
- }