Home › Forums › Ticket Products › Event Tickets Plus › Get all events future AND past via WP_Query?
- This topic has 4 replies, 4 voices, and was last updated 9 years, 5 months ago by
tjkelly.
-
AuthorPosts
-
November 4, 2016 at 7:42 am #1187683
tjkelly
ParticipantI am trying to get all events from the past and the future and am running this WP_Query and am noticing that I’m only getting events in the future:
$events = new WP_Query( array( 'post_type'=> 'tribe_events','posts_per_page' => - 1) );upon investigating there’s extra SQL being added to the actual query that is running, see below:
SELECT DISTINCT wp_posts.*, MIN(wp_postmeta.meta_value) as EventStartDate, MIN(tribe_event_end_date.meta_value) as EventEndDate FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) LEFT JOIN wp_postmeta as tribe_event_end_date ON ( wp_posts.ID = tribe_event_end_date.post_id AND tribe_event_end_date.meta_key = ‘_EventEndDate’ ) WHERE 1=1 AND wp_posts.ID NOT IN (1212,1217,1219) AND ( wp_postmeta.meta_key = ‘_EventStartDate’ ) AND wp_posts.post_type = ‘tribe_events’ AND (wp_posts.post_status = ‘publish’ OR wp_posts.post_status = ‘future’ OR wp_posts.post_status = ‘draft’ OR wp_posts.post_status = ‘pending’ OR wp_posts.post_status = ‘private’) AND (wp_postmeta.meta_value >= ‘2016-11-04 10:33:19’ OR (wp_postmeta.meta_value <= ‘2016-11-04 10:33:19’ AND tribe_event_end_date.meta_value >= ‘2016-11-04 10:33:19’ )) GROUP BY wp_posts.ID ORDER BY EventStartDate ASC, wp_posts.post_date ASC
specifically the code that is checking if the wp_postmeta.meta_value >= ‘2016-11-04 10:33:19’ OR (wp_postmeta.meta_value <= ‘2016-11-04 10:33:19’ AND tribe_event_end_date.meta_value >= ‘2016-11-04 10:33:19’ )) which appears to only be giving me events that are currently occurring or occurring in the future.
How can I remove these extra query parameters for a single query that I am running in a status page?
November 4, 2016 at 10:15 am #1187835tjkelly
ParticipantOK It looks like I’m getting somewhere. It appears to be the:
`
add_filter( ‘posts_where’, array( __CLASS__, ‘posts_where’ ), 10, 2 );
`that is in the method Tribe__Events__Query::pre_get_posts()
I tried running the following sandwiched between my query :
`
remove_filter( ‘posts_where’, array( ‘Tribe__Events__Query’, ‘posts_where’ ), 10);
$events = new WP_Query( array(
‘post_type’ => ‘tribe_events’,
‘posts_per_page’ => – 1
) );
add_filter( ‘posts_where’, array( ‘Tribe__Events__Query’, ‘posts_where’ ), 10, 2);`to remove the filter for this query but that is not effectively removing the filter.
Any ideas how, without modifying the source, I can get this to run in a WP_Query object?
November 4, 2016 at 8:14 pm #1188067Josh
ParticipantHey TJ,
Thanks for reaching out to us!
Try adding “supress_filters => true” to the query args there and see if it helps you to get what you’re looking for.
Let me know if this helps.
Thanks!
November 26, 2016 at 8:35 am #1197824Support Droid
KeymasterHey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.
Thanks so much!
The Events Calendar Support Team -
AuthorPosts
- The topic ‘Get all events future AND past via WP_Query?’ is closed to new replies.
