apply_filters( "get_{$adjacent}_post_sort", string $order_by, WP_Post $post, string $order )
- Since
- 2.5.0, 4.4.0, 4.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_sortget_previous_post_sort
Compatibility
- WordPress
- since 4.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 BYclause 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:2004get_adjacent_post()
Source code
* @since 4.9.0 Added the `$order` parameter. * * @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 LIMIT 1", $post, $order ); $query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort"; $key = md5( $query ); $last_changed = 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.
Signature, return type and hooks compared across 5 parsed releases.
4.9.0
Added the
$order parameter.from the docblock4.4.0
Added the
$post parameter.from the docblock2.5.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.