get_<adjacent>_post_sort

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

Description

apply_filters( 'get_<adjacent>_post_sort', (string) $order_by_p_post_date_order_limit_1, (WP_Post) $post ); 

The dynamic portion(s) of the hook name refer to the type of adjacency, next or previous..

Parameters (2)

0. $order_by_p_post_date_order_limit_1 (string) => "ORDER BY p.post_date $order LIMIT 1"
The order by p post date order limit 1.
1. $post (WP_Post)
WP_Post object.

Usage

To run the hook, copy the example below.
  1. $order_by_p_post_date_order_limit_1 = apply_filters( 'get_{$adjacent}_post_sort', $order_by_p_post_date_order_limit_1, $post ); 
  2.  
  3. if ( !empty( $order_by_p_post_date_order_limit_1 ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the get_<adjacent>_post_sort callback 
  2. function filter_get_adjacent_post_sort( $order_by_p_post_date_order_limit_1, $post ) { 
  3. // make filter magic happen here... 
  4. return $order_by_p_post_date_order_limit_1
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( "get_{$adjacent}_post_sort", 'filter_get_adjacent_post_sort', 10, 2 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( "get_{$adjacent}_post_sort", 'filter_get_adjacent_post_sort', 10, 2 ); 

Defined (1)

The filter is defined in the following location(s).

/wp-includes/link-template.php  
  1. $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post );