Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've got a custom post type (CPT) called event. Every event has got an associated meta_key called event_date.

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 event_date meta_key.

I managed to exclude events with empty event_date and order them correctly in the overall list of events by hooking into pre_get_posts hook.

Is it possible to hook into prev_post_link and next_post_link functions to specify meta_key select condition and meta_key order condition without the plugin? Is there a hook for it?

[P.S. note]: 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.

Many thanks, Dasha

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

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:

  1. Modifying Wordpress post status on Publish
  2. don't publish custom post type post if a meta data field isn't valid
share|improve this answer
add comment

prev and next_post_link ultimately call the get_adjacent_post function to query the db, which has filterable $join $where and $sort vars.

share|improve this answer
    
thanks. I've been trying to find an example of their usage without any luck. Also, I can't figure out how to hook into the get_adjacent_post to check if my SQL is constructed correctly. –  dashaluna Apr 21 '11 at 16:00
1  
I posted my working filters here: wordpress.stackexchange.com/a/139469/28957 –  cfx Mar 28 at 16:19
add comment

Your Answer

 
discard

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.