{"id":967745,"date":"2015-06-08T02:18:22","date_gmt":"2015-06-08T09:18:22","guid":{"rendered":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-events-with-start-date-after-now\/"},"modified":"2015-06-08T07:49:10","modified_gmt":"2015-06-08T14:49:10","slug":"filter-events-with-start-date-after-now","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-events-with-start-date-after-now\/","title":{"rendered":"Filter events with start date after now"},"content":{"rendered":"<p>Hello supporters,<\/p>\n<p>I got stuck in a problem that maybe you can help me with. <\/p>\n<p>In the solution I am working with, we have events from every kind. We have the community plugin, so people insert the events by themselves, and it is normal that they put a start date of the event in 1st of June and the end date at 27th of June, when they actually shall create a recurrent event instead.<\/p>\n<p>We want to avoid that behaviour, so we will only show events with start date after &#8220;now&#8221; (or the date on the filter bar). In order to do that I created this filter:<br \/>\n<code><br \/>\n\/\/All the events must start after the date we filter by<br \/>\nfunction start_date_strict($query) {<br \/>\n    $post_type = $query-&gt;query_vars['post_type']; <\/p>\n<p>    if ($post_type == 'tribe_events') {<\/p>\n<p>        $filterDate = current_time('Y-m-d H:i:s');<br \/>\n        if ( !empty( $_REQUEST['tribe-bar-date'] ) ) {<br \/>\n            $filterDate = $_REQUEST['tribe-bar-date'];<br \/>\n        }<\/p>\n<p>        $query-&gt;query_vars['meta_query'] = array(<br \/>\n                 array(         \/\/ restrict posts based on meta values<br \/>\n                    'key'     =&gt; '_EventStartDate',  \/\/ which meta to query<br \/>\n                    'value'   =&gt; $filterDate,  \/\/ value for comparison<br \/>\n                    'compare' =&gt; '&gt;=',          \/\/ method of comparison<br \/>\n                    'type'    =&gt; 'DATETIME')<br \/>\n                 );<br \/>\n    }<br \/>\n}<br \/>\nadd_filter( 'tribe_events_pre_get_posts', 'start_date_strict', 100, 1 );<br \/>\n<\/code><\/p>\n<p>The behaviour was the expected, but then I meshed up some other things that were working fine. For example, when I click in a venue to list all the events, the query is completely changed and does not filter by venue anymore (the same with the organizers).<\/p>\n<p>Is there any other filter more suitable for this purpose? I want it to work mainly on the main loop and also with the ajax filtering (date, category, etc).<\/p>\n<p>Thanks in advance for your awesome help! \ud83d\ude42<\/p>\n","protected":false},"template":"","class_list":["post-967745","topic","type-topic","status-closed","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Filter events with start date after now -<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-events-with-start-date-after-now\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Filter events with start date after now -\" \/>\n<meta property=\"og:description\" content=\"Hello supporters, I got stuck in a problem that maybe you can help me with. In the solution I am working with, we have events from every kind. We have the community plugin, so people insert the events by themselves, and it is normal that they put a start date of the event in 1st [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-events-with-start-date-after-now\/\" \/>\n<meta property=\"article:modified_time\" content=\"2015-06-08T14:49:10+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-events-with-start-date-after-now\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-events-with-start-date-after-now\/\",\"name\":\"Filter events with start date after now -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2015-06-08T09:18:22+00:00\",\"dateModified\":\"2015-06-08T14:49:10+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-events-with-start-date-after-now\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-events-with-start-date-after-now\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-events-with-start-date-after-now\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/theeventscalendar.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Topics\",\"item\":\"https:\/\/theeventscalendar.com\/support\/topics\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Calendar Products\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Events Calendar PRO\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/events-calendar-pro\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Filter events with start date after now\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\",\"url\":\"https:\/\/theeventscalendar.com\/support\/\",\"name\":\"\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Filter events with start date after now -","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-events-with-start-date-after-now\/","og_locale":"en_US","og_type":"article","og_title":"Filter events with start date after now -","og_description":"Hello supporters, I got stuck in a problem that maybe you can help me with. In the solution I am working with, we have events from every kind. We have the community plugin, so people insert the events by themselves, and it is normal that they put a start date of the event in 1st [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-events-with-start-date-after-now\/","article_modified_time":"2015-06-08T14:49:10+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-events-with-start-date-after-now\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-events-with-start-date-after-now\/","name":"Filter events with start date after now -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2015-06-08T09:18:22+00:00","dateModified":"2015-06-08T14:49:10+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-events-with-start-date-after-now\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-events-with-start-date-after-now\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-events-with-start-date-after-now\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/theeventscalendar.com\/support\/"},{"@type":"ListItem","position":2,"name":"Topics","item":"https:\/\/theeventscalendar.com\/support\/topics\/"},{"@type":"ListItem","position":3,"name":"Calendar Products","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/"},{"@type":"ListItem","position":4,"name":"Events Calendar PRO","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/events-calendar-pro\/"},{"@type":"ListItem","position":5,"name":"Filter events with start date after now"}]},{"@type":"WebSite","@id":"https:\/\/theeventscalendar.com\/support\/#website","url":"https:\/\/theeventscalendar.com\/support\/","name":"","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/theeventscalendar.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/967745","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/967745\/revisions"}],"predecessor-version":[{"id":967750,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/967745\/revisions\/967750"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=967745"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}