get_<adjacent>_post_where

Filters the WHERE clause in the SQL for an adjacent post query.

Description

apply_filters( 'get_<adjacent>_post_where', (string) $wpdb_prepare_where_p_post_date_op_s_and_p_post_type_s_where_current_post_date_post_post_type, (bool) $in_same_term, (array) $excluded_terms, (string) $taxonomy, (WP_Post) $post ); 

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

Parameters (5)

0. $wpdb_prepare_where_p_post_date_op_s_and_p_post_type_s_where_current_post_date_post_post_type (string)
The wpdb prepare where p post date op s and p post type s where current post date post post type.
1. $in_same_term (bool)
Whether post should be in a same taxonomy term.
2. $excluded_terms (array)
Array of excluded term IDs.
3. $taxonomy (string)
Taxonomy. Used to identify the term used when $in_same_term is true.
4. $post (WP_Post)
WP_Post object.

Usage

To run the hook, copy the example below.
  1. $wpdb_prepare_where_p_post_date_op_s_and_p_post_type_s_where_current_post_date_post_post_type = apply_filters( 'get_{$adjacent}_post_where', $wpdb_prepare_where_p_post_date_op_s_and_p_post_type_s_where_current_post_date_post_post_type, $in_same_term, $excluded_terms, $taxonomy, $post ); 
  2.  
  3. if ( !empty( $wpdb_prepare_where_p_post_date_op_s_and_p_post_type_s_where_current_post_date_post_post_type ) ) { 
  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_where callback 
  2. function filter_get_adjacent_post_where( $wpdb_prepare_where_p_post_date_op_s_and_p_post_type_s_where_current_post_date_post_post_type, $in_same_term, $excluded_terms, $taxonomy, $post ) { 
  3. // make filter magic happen here... 
  4. return $wpdb_prepare_where_p_post_date_op_s_and_p_post_type_s_where_current_post_date_post_post_type
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( "get_{$adjacent}_post_where", 'filter_get_adjacent_post_where', 10, 5 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( "get_{$adjacent}_post_where", 'filter_get_adjacent_post_where', 10, 5 ); 

Defined (1)

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

/wp-includes/link-template.php  
  1. $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare( "WHERE p.post_date $op %s AND p.post_type = %s $where", $current_post_date, $post->post_type ), $in_same_term, $excluded_terms, $taxonomy, $post );