I am building an event manager. One of the template files I have is events-single.php which displays single events. At the bottom of this I have next and previous events using next_post_link and previous_post_link. The problem is that those functions proceed through the events in order of published date rather than event date. (I have a meta key _fulldate setup on the CPT for this). When I was building events-archive.php file I overcame a similar problem by doing something like this

$query = new WP_Query( array ( 
'post_type' => 'events', 
'orderby' => 'meta_value', 
'meta_key' => '_fulldate', 
'order' => 'ASC')

However when I try that on events-single.php it makes all the events display on the page.

Ultimatly I want events-single.php to behave like a single page but then allow me control over the query as above. Is this possible or will I have to do a second loop for the Previous and Next links

1 Answer 1


Take a look here: specify meta_key / meta_value condition for prev_post_link and next_post_link

Which ultimately leads to this plugin, which accesses the get_adjacent_post function mentioned above: Ambrosite Next/Previous Post Link Plus

And looks like it would fit your needs by allowing you to specificy a meta_value for the next/prev post hook.

  • Thanks for that link - it's the right track all right, but I'm not really understanding how to implement the filters and I cant find a full example anywhere. Anyway It looks to be a bit more complex than I want to get into at the moment and it's not a huge issue on the theme as in context I don't think previous next events will be that important to most people so I'm leaving it out for this version. BTW the theme is for resale so I want to avoid plugins. Commented Mar 15, 2012 at 23:06

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.