Question

Is this possible? How can i change the query for adjacent posts and add 'post_status=future' to display next and previous posts for scheduled ones?

I suppose i should use some kind of filter, but could someone show me how? :)

Was it helpful?

Solution

You can do this by using the get_{$adjacent}_post_where filter.

Basically all we are doing is replacing the part of the query that says "find published posts" with "find published or future posts".

/**
 * Amend the 'WHERE' clause in the SQL query to find an adjacent post
 *
 * @param required string $where  The default 'WHERE' clause in the query
 * @param boolean $in_same_term   Whether or not the adjacent post should be in the same taxonomy term (not required here)
 * @param array $excluded_terms   The ID's of terms that should be excluded (not required here)
 * @return string                 The updated, custom 'WHERE' clause
 */
add_filter('get_previous_post_where', 'my_add_future_posts_to_nav', 3, 99);
add_filter('get_next_post_where', 'my_add_future_posts_to_nav', 3, 99);
function my_add_future_posts_to_nav($where, $in_same_term, $excluded_terms){

    return str_replace("p.post_status = 'publish'", "p.post_status IN ('publish', 'future')", $where);

}

While I can't seem to find any Filter Reference for get_{$adjacent}_post_where, there is a Developer Code Reference which you may find useful.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top