Title: get_previous_post
Published: April 25, 2014
Last modified: February 24, 2026

---

# get_previous_post( bool $in_same_term = false, int[]|string $excluded_terms, string $taxonomy ): 󠀁[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)󠁿|null|string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_previous_post/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_previous_post/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_previous_post/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_previous_post/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_previous_post/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_previous_post/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_previous_post/?output_format=md#wp--skip-link--target)

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

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_previous_post/?output_format=md#parameters)󠁿

 `$in_same_term`booloptional

Whether post should be in the same taxonomy term.

Default:`false`

`$excluded_terms`int[]|stringoptional

Array or comma-separated list of excluded term IDs.
 Default empty.

`$taxonomy`stringoptional

Taxonomy, if `$in_same_term` is true. Default `'category'`.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_previous_post/?output_format=md#return)󠁿

 [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)|null|string
Post object if successful. Null if global `$post` is not set.
 Empty string if no
corresponding post exists.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_previous_post/?output_format=md#source)󠁿

    ```php
    function get_previous_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) {
    	return get_adjacent_post( $in_same_term, $excluded_terms, true, $taxonomy );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/link-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/link-template.php#L1790)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/link-template.php#L1790-L1792)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_previous_post/?output_format=md#related)󠁿

| Uses | Description | 
| [get_adjacent_post()](https://developer.wordpress.org/reference/functions/get_adjacent_post/)`wp-includes/link-template.php` |

Retrieves the adjacent post.

  |

| Used by | Description | 
| [previous_post()](https://developer.wordpress.org/reference/functions/previous_post/)`wp-includes/deprecated.php` |

Prints a link to the previous post.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_previous_post/?output_format=md#changelog)󠁿

| Version | Description | 
| [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_previous_post/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/get_previous_post/?output_format=md#comment-content-757)
 2.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_previous_post/#comment-757)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_previous_post%2F%23comment-757)
    Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_previous_post%2F%23comment-757)
 4. **Example**
 5.     ```php
        <?php
        $prev_post = get_previous_post();
        if ( ! empty( $prev_post ) ): ?>
        	<a href="<?php echo get_permalink( $prev_post->ID ); ?>">
        		<?php echo apply_filters( 'the_title', $prev_post->post_title ); ?>
        	</a>
        <?php endif; ?>
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_previous_post%2F%3Freplytocom%3D757%23feedback-editor-757)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_previous_post%2F)
before being able to contribute a note or feedback.