我们有一个处理事件的插件。这个插件不处理重复事件,所以我们想添加这个功能。
我已经编写了一个查询,该查询正在运行并引入我们想要的事件。它看起来像这样:
SELECT posts.*, metaStartDate.meta_value as EventStartDate, meta.meta_value as EventRepeats, metaTimeSpans.meta_value as EventTimeRanges
FROM $wpdb->posts posts
LEFT JOIN $wpdb->postmeta meta ON (posts.ID = meta.post_id AND meta.meta_key = '_EventRepeats')
LEFT JOIN $wpdb->postmeta metaStartDate ON (posts.ID = metaStartDate.post_id AND metaStartDate.meta_key = '_EventStartDate')
LEFT JOIN $wpdb->postmeta metaRepeatsUntil ON (posts.ID = metaRepeatsUntil.post_id AND metaRepeatsUntil.meta_key = '_EventRepeatsUntil')
LEFT JOIN $wpdb->postmeta metaTimeSpans ON (posts.ID = metaTimeSpans.post_id AND metaTimeSpans.meta_key = '_EventTimeRanges')
WHERE posts.post_type = 'tribe_events'
AND posts.post_status = 'publish'
AND meta.meta_value != 'once'
AND '$queryDate 00:00:00' BETWEEN metaStartDate.meta_value AND metaRepeatsUntil.meta_value
正如我所提到的,这是获取我们想要的事件,但是我如何将它们添加到 Wordpress 循环中,以便像这样have_posts()
工作the_post()
?
编辑:看起来正确的答案是使用 WP_Query,但是有没有办法在 WP_Query 中进行类似的大查询?