Title: get_{$adjacent}_post_sort
Published: April 25, 2014
Last modified: August 20, 2026

---

# apply_filters( “get_{$adjacent}_post_sort”, string $order_by, WP_Post $post, string $order )

## In this article

 * [Description](https://developer.wordpress.org/reference/hooks/get_adjacent_post_sort/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/hooks/get_adjacent_post_sort/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/get_adjacent_post_sort/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/get_adjacent_post_sort/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/get_adjacent_post_sort/?output_format=md#changelog)

Filters the ORDER BY clause in the SQL for an adjacent post query.

## 󠀁[Description](https://developer.wordpress.org/reference/hooks/get_adjacent_post_sort/?output_format=md#description)󠁿

The dynamic portion of the hook name, `$adjacent`, refers to the type of adjacency,‘
next’ or ‘previous’.

Possible hook names include:

 * `get_next_post_sort`
 * `get_previous_post_sort`

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

 `$order_by`string

The `ORDER BY` clause in the SQL.

`$post`[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)

[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/) object.

`$order`string

Sort order. `'DESC'` for previous post, `'ASC'` for next.

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

    ```php
    $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order, p.ID $order LIMIT 1", $post, $order );
    ```

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

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

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

Retrieves the adjacent post.

  |

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

| Version | Description | 
| [6.9.0](https://developer.wordpress.org/reference/since/6.9.0/) | Adds ID sort to ensure deterministic ordering for posts with identical dates. | 
| [4.9.0](https://developer.wordpress.org/reference/since/4.9.0/) | Added the `$order` parameter. | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Added the `$post` parameter. | 
| [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. |

## User Contributed Notes

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