WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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.

share|improve this answer
@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 Aug 12 '11 at 18:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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