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.
- $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 );
- if ( !empty( $wpdb_prepare_where_p_post_date_op_s_and_p_post_type_s_where_current_post_date_post_post_type ) ) {
- // everything has led up to this point...
- }
- The following example is for adding a hook callback.
- // define the get_<adjacent>_post_where callback
- 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 ) {
- // make filter magic happen here...
- return $wpdb_prepare_where_p_post_date_op_s_and_p_post_type_s_where_current_post_date_post_post_type;
- };
- // add the filter
- add_filter( "get_{$adjacent}_post_where", 'filter_get_adjacent_post_where', 10, 5 );
- To remove a hook callback, use the example below.
- // remove the filter
- 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
- $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 );