get_next_post_sort
Filters the ORDER BY clause in the SQL for an adjacent post query.
This is one of the variants of the dynamic hook get_(adjacent)_post_sort
Usage
add_filter( 'get_next_post_sort', 'wp_kama_get_next_post_sort_filter', 10, 3 );
/**
* Function for `get_next_post_sort` filter-hook.
*
* @param string $order_by The `ORDER BY` clause in the SQL.
* @param WP_Post $post WP_Post object.
* @param $order
*
* @return string
*/
function wp_kama_get_next_post_sort_filter( $order_by, $post, $order ){
// filter...
return $order_by;
}
- $order_by(string)
- The
ORDER BYclause in the SQL. - $post(WP_Post)
- WP_Post object.
- $order
- -
Changelog
| Since 2.5.0 | Introduced. |
| Since 4.4.0 | Added the $post parameter. |
| Since 4.9.0 | Added the $order parameter. |
| Since 6.9.0 | Adds ID sort to ensure deterministic ordering for posts with identical dates. |
Where the hook is called
get_next_post_sort
wp-includes/link-template.php 2012
$sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order, p.ID $order LIMIT 1", $post, $order );