I have a custom post type events and am displaying these events using archive-events.php and single-events.php from the template hierarchy. I have a custom query in archive-events.php

$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$events_query = new WP_Query( array (
  'post_type' => 'events',
  'orderby' => 'meta_value',
  'meta_key' => '_fulldate',
  'order' => 'ASC',
  'paged' => $paged,
  'meta_query' => array ( array(
      'key' => '_fulldate',
      'value' => $cutoff_date,
      'type' => 'numeric',
      'compare' => '>' ) ) )

This displays the events in order of event date ( as opposed to published date ). All works fine until I put previous_post_link() and next_post_link() into single-events.php. What happens then is that the next and previous links take me to the next and previous event by published date as opposed to by event date.

I am a bit confused about how events-single.php is meant to know which is the next event. Should I be doing some kind of query on there as well, because I'm not at the moment? It's just a standard 'single' file.

Could anybody help me out I have been up and down this and cant find out how to do it.

1 Answer 1


You probably need a filter on get_{$adjacent}_post_join and get_{$adjacent}_post_sort to get those to work.

Apologies, but I don't have time right now to work up the actual filters and debug them, but maybe that will get you started.

  • Thanks. I am surprised there's not some simple solution like a function for it or something. I would have thought that it would be in common use. Thanks for pointing me in the right direction anyway, but I doubt if I'd be able to work it out from the source code; mainly because I wouldn't know where to start, and I dont get the idea ... so if you do have any more information on it in the future I'd appreciate if you posted it here when you eventually do have time. For now I think I'll leave the next and previous events out of my theme unless someone else posts here as they're not vital. Commented Nov 28, 2012 at 20:02
  • Actually played around with it for a while and though I still don't really know much about it, I have a lot better idea than I did an hour ago. I wonder if you have time to just give me a bare bones an example of how such a filter might work. I'm sure I could work out details themselves but I don't know where to put it or how to get it actually operating in any way at all .. I read this post wordpress.org/support/topic/… which seems to be in the same general area but he is talking about editing core files and anyway I tried it but it gave no effect. Commented Nov 28, 2012 at 21:03

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.