I’ve got a custom post type (CPT) called
event. Every event has got an associated
I want to make sure that events with empty
event_date won’t appear in my list of all events and in the prev/next event navigation when viewing a single event. I also want to order events by the
I managed to exclude events with empty
event_date and order them correctly in the overall list of events by hooking into
Is it possible to hook into
next_post_link functions to specify
meta_key select condition and
meta_key order condition without the plugin? Is there a hook for it?
I also tried using Ambrosite Next/Previous Post Link Plus plugin. I figured out how to order events by meta_key. However, the events with empty
event_date meta_value are still appearing in the prev/next navigation when viewing a single event.
It doesn’t seem to be possible to hook into WP before the plugin, because I think it constructs its own SQL. I could use
ex_posts with the list of all the event ids to exclude, but that would mean extra query to the db.
prev and next_post_link ultimately call the get_adjacent_post function to query the db, which has filterable $join $where and $sort vars.
I ended up using the Ambrosite Next/Previous Post Link Plus plugin.
As to an empty
event_date meta key – I have added some code to prevent a post from being saved if meta key value isn’t correct.
Have a look at this posts: