Filter hook 'get_{$adjacent}_post_where'

in WP Core File wp-includes/link-template.php at line 1983

View Source

get_{$adjacent}_post_where

Filter Hook
Description
Filters the WHERE clause in the SQL for an adjacent post query. The dynamic portion of the hook name, `$adjacent`, refers to the type of adjacency, 'next' or 'previous'. Possible hook names include: - `get_next_post_where` - `get_previous_post_where`

Hook Information

File Location wp-includes/link-template.php View on GitHub
Hook Type Filter
Line Number 1983

Hook Parameters

Type Name Description
string $where The `WHERE` clause in the SQL.
bool $in_same_term Whether post should be in the same taxonomy term.
int[]|string $excluded_terms Array of excluded term IDs. Empty string if none were provided.
string $taxonomy Taxonomy. Used to identify the term used when `$in_same_term` is true.
WP_Post $post WP_Post object.

Usage Examples

Basic Usage
<?php
// Hook into get_{$adjacent}_post_where
add_filter('get_{$adjacent}_post_where', 'my_custom_filter', 10, 5);

function my_custom_filter($where, $in_same_term, $excluded_terms, $taxonomy, $post) {
    // Your custom filtering logic here
    return $where;
}

Source Code Context

wp-includes/link-template.php:1983 - How this hook is used in WordPress core
<?php
1978  	 * @param bool         $in_same_term   Whether post should be in the same taxonomy term.
1979  	 * @param int[]|string $excluded_terms Array of excluded term IDs. Empty string if none were provided.
1980  	 * @param string       $taxonomy       Taxonomy. Used to identify the term used when `$in_same_term` is true.
1981  	 * @param WP_Post      $post           WP_Post object.
1982  	 */
1983  	$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 );
1984  
1985  	/**
1986  	 * Filters the ORDER BY clause in the SQL for an adjacent post query.
1987  	 *
1988  	 * The dynamic portion of the hook name, `$adjacent`, refers to the type

PHP Documentation

<?php
/**
	 * Filters the WHERE clause in the SQL for an adjacent post query.
	 *
	 * The dynamic portion of the hook name, `$adjacent`, refers to the type
	 * of adjacency, 'next' or 'previous'.
	 *
	 * Possible hook names include:
	 *
	 *  - `get_next_post_where`
	 *  - `get_previous_post_where`
	 *
	 * @since 2.5.0
	 * @since 4.4.0 Added the `$taxonomy` and `$post` parameters.
	 *
	 * @param string       $where          The `WHERE` clause in the SQL.
	 * @param bool         $in_same_term   Whether post should be in the same taxonomy term.
	 * @param int[]|string $excluded_terms Array of excluded term IDs. Empty string if none were provided.
	 * @param string       $taxonomy       Taxonomy. Used to identify the term used when `$in_same_term` is true.
	 * @param WP_Post      $post           WP_Post object.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 5
  • File: wp-includes/link-template.php
Related Hooks

Related hooks will be displayed here in future updates.