I have a page with two sections, each uses a different WP_Query()
to pull in events
, which are a custom post type. Each WP_Query()
queries a meta_key
for the event date so that Section 1 only displays upcoming events
and Section 2 displays past events
.
The upcoming events
in Section 1 display all relevant information on my page, so clicking them is not possible.
The past events
in Section 2 only display the event
title and are clickable. When users click a past event
they link to a custom single-event.php
template for the past event
.
I want to display Previous/Next navigation in the single-event.php
template, but the navigation should only point to past events
.
I tried using next_post_link()
and previous_post_link()
but these will link to upcoming events
too, which I do not want. I can probably setup a new WP_Query()
on my single-event.php
and loop through it to get the Prev/Next IDs, but repeating the query seems like a drastic step.
I would really appreciate some insight on a way to filter out upcoming events
from my Previous/Next post links. I've seen this question but I would prefer not to use a plugin.
get_adjacent_post
function.WP_Query
, then inspect$your_query_object->request
, which will reveal a good bit of the SQL you'll need to pull it off.