wppaste
WordPress

apply_filters( "get_{$adjacent}_post_sort", string $order_by, WP_Post $post, string $order )

Since
2.5.0, 4.4.0, 4.9.0, 6.9.0
Filters the ORDER BY clause in the SQL for an adjacent post query.

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

Compatibility

WordPress
since 6.9.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Parameters

$order_bystring
The ORDER BY clause in the SQL.
$postWP_Post
WP_Post object.
$orderstring
Sort order. 'DESC' for previous post, 'ASC' for next.

Where this hook fires · 1

  • wp-includes/link-template.php:2012get_adjacent_post()

Source code

	 * @since 6.9.0 Adds ID sort to ensure deterministic ordering for posts with identical dates.	 *	 * @param string $order_by The `ORDER BY` clause in the SQL.	 * @param WP_Post $post    WP_Post object.	 * @param string  $order   Sort order. 'DESC' for previous post, 'ASC' for next.	 */	$sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order, p.ID $order LIMIT 1", $post, $order ); 	$query        = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort";	$key          = md5( $query );	$last_changed = (array) wp_cache_get_last_changed( 'posts' );	if ( $in_same_term || ! empty( $excluded_terms ) ) {		$last_changed[] = wp_cache_get_last_changed( 'terms' );

Changelog

Introduced in 2.5.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.9.0
Adds ID sort to ensure deterministic ordering for posts with identical dates.from the docblock
4.9.0
Added the $order parameter.from the docblock
4.4.0
Added the $post parameter.from the docblock
2.5.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.