I am using the More Fields and More Types plugins to create a custom post type called product. This custom type is based on the Post type.

One of the fields is named lot which is an integer representing a Lot # for an auction.

I created a custom category page which generates a list of links for each Lot, ordered by the lot field. This works great.

$args = array(
  'post_type' => array('product'), 
  'cat' => 3,
  'meta_key' => 'lot',
  'orderby' => 'meta_value_num',
  'order' => 'ASC'

However... when you click on one of the lots, the Previous & Next post links aren't ordered by the lot field anymore, they are ordered by publish date (which is the WP default). I am trying to figure out how I can change this default sort order for previous_post_link() and next_post_link() to use custom field lot instead of Publish date.

1 Answer 1


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.

  • @Manny Fleurmond it's included in SQL query, passed through the filter. Might not be very convenient, but nothing overly complex to get it from there.
    – Rarst
    Commented Aug 12, 2011 at 18:44
  • I'm having the same issue but the upvoted answer by @Rarst is not clear to me! Does that mean that I need to tweak the code in the link-template.php file? Commented May 6, 2021 at 16:28
  • @EmKarimifar there is no need to edit core code, because the relevant part can be filtered, however you would need to modify a raw SQL to what you need, which isn't trivial.
    – Rarst
    Commented May 12, 2021 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.