Custom Post Type “Event”: chronological list of recurring events

i’m looking for a good and easy way to have a custom post type “event” that can have multiple dates. (I have tested about 20 plugins). I think i have no problem building a metabox allowing the user to duplicate the field group “date and time” multiple times. But how would a query look like that creates a chronological list of events from the meta data?

(The project is a playing schedule for a theatre. Productions play on several dates.) Thank you!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Here’s a plan:

  1. Store the dates as individual custom fields with the same meta_key (ex: start_date)
  2. JOIN the wp_posts table with the wp_postmeta table, without a GROUP BY (to allow the same event to appear more than once)
  3. ORDER BY start_date

The full query would look like this:

SELECT wp_posts.*, meta_value AS start_date
FROM wp_posts INNER JOIN wp_postmeta ON (ID = post_ID)
WHERE post_type = 'event'
AND post_status = 'publish'
AND meta_key = 'start_date'
ORDER BY start_date

PS: This requires you store the date in YYYY-MM-DD format, which you should do anyway, for compatibility with mysql2date() etc.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x