I got a tricky problem I need to solve. So say, you have a custom post type of
event, then this event has a scheduled event date by a custom field. And this event is recurring, like every Saturday since the
event date until February 3 2019.
And, you want a way so that
WP_Query will output those
event and sort them by their
event_date: Jan 19 2019
recur until: Feb 3 2019
That means, when we retrieve post via WP_Query, there would be at least 3
events showing up:
- Event A Jan 19.
- Event A Jan 26.
- Event A Feb 3.
tricky huh? Not sure if this "cloning" and just changing that 'event date'custom field, and order them ASC is possible just by merely
WP_Query, but let me know as that will save me alot of time.
So, moving forward, the possible solution I am currently working now is to: clone that post 3 times (for all Saturdays between Jan 19 to February 3). Then update those clone post with the respective
event date. In this way, natively,
WP_Query would be able to list those post. Then, for each cloned post we add 2 meta keys:
_master_post_id is to allow us to delegate and redirect user to the actual event post. Like if you will display a cloned eecurring event in frontend, the
slug you will use is the slug of the
_is_cloned meta key is to, hopefully, be used so that in the post listing in the admin backend,
wp-admin, the cloned posts will not appear, so that editors can't be confused on which event is the 'master' and 'cloned'. (Note that, I'll make it so that updating a master event will also update its cloned events). This way, only the master will show up.
I imagine excluding the cloned posts in the post listing can be solved by
pre_get_posts(), (if post has meta key _is_cloned, then exclude) but how can I be assured that all query in the admin backend will behave like this? i.e. exclude on ajax result of post listing of ACF plugin when selecting posts; exclude on post listing when selecting menu items in
Appearance -> Menus?
Hope somebody can be consulted with this. or if there's a better approach?