{"id":67969,"date":"2013-09-27T05:47:03","date_gmt":"2013-09-27T12:47:03","guid":{"rendered":"https:\/\/tri.be\/support\/forums\/topic\/pre_get_posts-when-loading-calendar-view-with-ajax\/"},"modified":"2015-07-07T06:28:45","modified_gmt":"2015-07-07T13:28:45","slug":"pre_get_posts-when-loading-calendar-view-with-ajax","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/pre_get_posts-when-loading-calendar-view-with-ajax\/","title":{"rendered":"pre_get_posts when loading calendar view with Ajax"},"content":{"rendered":"<p>Cheers guys!<\/p>\n<p>I have a filter running on pre_get_posts and it works fine as long as content is not loaded via Ajax.<\/p>\n<p>Specifically I am excluding some events from being displayed everywhere except in the very category they belong to. This works fine as long as I call up the corresponding view directly. Say all the events that I want to be hidden are in October (http:\/\/gastgewerbe-magazin.de\/veranstaltungen\/2013-10\/), if I go there directly (empty\/new tab, paste URL, hit Enter) the filter works fine. Now if I go there from another month, let it be September (http:\/\/gastgewerbe-magazin.de\/veranstaltungen\/2013-09) and then scroll down and use the &#8220;next month&#8221; link below the calendar the filter isn&#8217;t kicking in and all events are shown. You should be able to see the differences between the &#8220;ajaxified&#8221; version and the normal one quite easily.<\/p>\n<p>So I guess the Ajax call or they way how it retrieves the events (through tribe_get_view()?) somehow bypasses the pre_get_posts filter. Or I&#8217;m just plain stupid and can&#8217;t see what I&#8217;m doing wrong. \ud83d\ude1b<\/p>\n<p>I&#8217;ll just paste in what I have in functions.php in my theme:<\/p>\n<p>function ggm_remove_events_from_display($query)<br \/>\n{<br \/>\n\tif<br \/>\n\t(<br \/>\n\t\t$query-&gt;query[&#8216;post_type&#8217;] === &#8216;tribe_events&#8217;<br \/>\n\t\t&amp;&amp;<br \/>\n\t\t(<br \/>\n\t\t\tarray_key_exists(&#8216;tribe_events_cat&#8217;, $query-&gt;query) === false<br \/>\n\t\t\t||<br \/>\n\t\t\t(<br \/>\n\t\t\t\tarray_key_exists(&#8216;tribe_events_cat&#8217;, $query-&gt;query) === true<br \/>\n\t\t\t\t&amp;&amp;<br \/>\n\t\t\t\t$query-&gt;query[&#8216;tribe_events_cat&#8217;] !== &#8216;anuga-rahmenprogramm&#8217;<br \/>\n\t\t\t)<br \/>\n\t\t)<br \/>\n\t)<br \/>\n\t{<br \/>\n\t\t$hide_categories_args = array<br \/>\n\t\t(<br \/>\n\t\t\t&#8216;taxonomy&#8217; =&gt; &#8216;tribe_events_cat&#8217;,<br \/>\n\t\t\t&#8216;terms&#8217; =&gt; array(&#8216;anuga-rahmenprogramm&#8217;),<br \/>\n\t\t\t&#8216;field&#8217; =&gt; &#8216;slug&#8217;,<br \/>\n\t\t\t&#8216;include_children&#8217; =&gt; true,<br \/>\n\t\t\t&#8216;operator&#8217; =&gt; &#8216;NOT IN&#8217;<br \/>\n\t\t);<\/p>\n<p>\t\t$query-&gt;query[&#8216;tax_query&#8217;][] = $hide_categories_args;<br \/>\n\t}<br \/>\n}<br \/>\nadd_filter(&#8216;pre_get_posts&#8217;, &#8216;ggm_remove_events_from_display&#8217;);<\/p>\n<p>Btw, how do I post code snippets here? HTML tags seem to get swallowed.<\/p>\n","protected":false},"template":"","class_list":["post-67969","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>pre_get_posts when loading calendar view with Ajax -<\/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\/pre_get_posts-when-loading-calendar-view-with-ajax\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"pre_get_posts when loading calendar view with Ajax -\" \/>\n<meta property=\"og:description\" content=\"Cheers guys! I have a filter running on pre_get_posts and it works fine as long as content is not loaded via Ajax. Specifically I am excluding some events from being displayed everywhere except in the very category they belong to. This works fine as long as I call up the corresponding view directly. Say all [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/pre_get_posts-when-loading-calendar-view-with-ajax\/\" \/>\n<meta property=\"article:modified_time\" content=\"2015-07-07T13:28:45+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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/pre_get_posts-when-loading-calendar-view-with-ajax\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/pre_get_posts-when-loading-calendar-view-with-ajax\/\",\"name\":\"pre_get_posts when loading calendar view with Ajax -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2013-09-27T12:47:03+00:00\",\"dateModified\":\"2015-07-07T13:28:45+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/pre_get_posts-when-loading-calendar-view-with-ajax\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/pre_get_posts-when-loading-calendar-view-with-ajax\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/pre_get_posts-when-loading-calendar-view-with-ajax\/#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\":\"pre_get_posts when loading calendar view with Ajax\"}]},{\"@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":"pre_get_posts when loading calendar view with Ajax -","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\/pre_get_posts-when-loading-calendar-view-with-ajax\/","og_locale":"en_US","og_type":"article","og_title":"pre_get_posts when loading calendar view with Ajax -","og_description":"Cheers guys! I have a filter running on pre_get_posts and it works fine as long as content is not loaded via Ajax. Specifically I am excluding some events from being displayed everywhere except in the very category they belong to. This works fine as long as I call up the corresponding view directly. Say all [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/pre_get_posts-when-loading-calendar-view-with-ajax\/","article_modified_time":"2015-07-07T13:28:45+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/pre_get_posts-when-loading-calendar-view-with-ajax\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/pre_get_posts-when-loading-calendar-view-with-ajax\/","name":"pre_get_posts when loading calendar view with Ajax -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2013-09-27T12:47:03+00:00","dateModified":"2015-07-07T13:28:45+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/pre_get_posts-when-loading-calendar-view-with-ajax\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/pre_get_posts-when-loading-calendar-view-with-ajax\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/pre_get_posts-when-loading-calendar-view-with-ajax\/#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":"pre_get_posts when loading calendar view with Ajax"}]},{"@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\/67969","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\/67969\/revisions"}],"predecessor-version":[{"id":981066,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/67969\/revisions\/981066"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=67969"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}