How to order adjacent posts (prev / next) by custom field value?

You can filter SQL to change to your condition in get_adjacent_post() ( source ) :

$sort  = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );

Or filter link altogether in adjacent_post_link() ( source ) :

echo apply_filters( "{$adjacent}_post_link", $format, $link );

PS $adjacent can be next or previous.

Leave a Comment