{"id":992821,"date":"2015-08-03T11:33:26","date_gmt":"2015-08-03T18:33:26","guid":{"rendered":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/query-modifications-with-tribe_events_pre_get_posts-not-honored-via-ajax\/"},"modified":"2015-08-04T07:40:46","modified_gmt":"2015-08-04T14:40:46","slug":"query-modifications-with-tribe_events_pre_get_posts-not-honored-via-ajax","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/query-modifications-with-tribe_events_pre_get_posts-not-honored-via-ajax\/","title":{"rendered":"Query modifications with tribe_events_pre_get_posts not honored via AJAX"},"content":{"rendered":"<p>I&#8217;m trying to remove an Event Category (id:462) from all event queries (except that category&#8217;s landing page) and it works fine on page load, but doesn&#8217;t seem to be honored when query results are loaded via ajax.<\/p>\n<p>The following code works on events page load, and if I were to load an event search query directly on a page (i.e., reloading the results), but if I do anything that would reload the query via AJAX it is not honored (such as paginating, or entering a new search). When that happens, events of the category 462 still show up.<\/p>\n<p>I&#8217;m thinking that somewhere the date query is superseding this query modifications, but no matter what I set as a the priority of this modification, the AJAX calls are still not catching it. Any ideas?<\/p>\n<pre><code>\/\/ Tribe Events modifications to the query\nfunction events_mod( $query ) {\n  if( !is_admin() &amp;&amp; $query-&gt;is_main_query() &amp;&amp; !is_tax(&#039;tribe_events_cat&#039;) &amp;&amp; !tribe_is_event() &amp;&amp; ( tribe_is_past() || tribe_is_upcoming() ) ) {\n    $taxquery = array(\n        array(\n          &#039;taxonomy&#039; =&gt; &#039;tribe_events_cat&#039;,\n          &#039;field&#039;    =&gt; &#039;id&#039;,\n          &#039;terms&#039;    =&gt; array( 462 ),\n          &#039;operator&#039; =&gt; &#039;NOT IN&#039;\n        )\n      );\n    $query-&gt;set( &#039;tax_query&#039;, $taxquery );\n  }\n  return $query;\n}\n\nadd_action( &#039;tribe_events_pre_get_posts&#039;, &#039;events_mod&#039;, 1);<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-992821","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>Query modifications with tribe_events_pre_get_posts not honored via 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\/query-modifications-with-tribe_events_pre_get_posts-not-honored-via-ajax\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Query modifications with tribe_events_pre_get_posts not honored via AJAX -\" \/>\n<meta property=\"og:description\" content=\"I&#8217;m trying to remove an Event Category (id:462) from all event queries (except that category&#8217;s landing page) and it works fine on page load, but doesn&#8217;t seem to be honored when query results are loaded via ajax. The following code works on events page load, and if I were to load an event search query [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/query-modifications-with-tribe_events_pre_get_posts-not-honored-via-ajax\/\" \/>\n<meta property=\"article:modified_time\" content=\"2015-08-04T14:40:46+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\/query-modifications-with-tribe_events_pre_get_posts-not-honored-via-ajax\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/query-modifications-with-tribe_events_pre_get_posts-not-honored-via-ajax\/\",\"name\":\"Query modifications with tribe_events_pre_get_posts not honored via AJAX -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2015-08-03T18:33:26+00:00\",\"dateModified\":\"2015-08-04T14:40:46+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/query-modifications-with-tribe_events_pre_get_posts-not-honored-via-ajax\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/query-modifications-with-tribe_events_pre_get_posts-not-honored-via-ajax\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/query-modifications-with-tribe_events_pre_get_posts-not-honored-via-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\":\"Query modifications with tribe_events_pre_get_posts not honored via 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":"Query modifications with tribe_events_pre_get_posts not honored via 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\/query-modifications-with-tribe_events_pre_get_posts-not-honored-via-ajax\/","og_locale":"en_US","og_type":"article","og_title":"Query modifications with tribe_events_pre_get_posts not honored via AJAX -","og_description":"I&#8217;m trying to remove an Event Category (id:462) from all event queries (except that category&#8217;s landing page) and it works fine on page load, but doesn&#8217;t seem to be honored when query results are loaded via ajax. The following code works on events page load, and if I were to load an event search query [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/query-modifications-with-tribe_events_pre_get_posts-not-honored-via-ajax\/","article_modified_time":"2015-08-04T14:40:46+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\/query-modifications-with-tribe_events_pre_get_posts-not-honored-via-ajax\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/query-modifications-with-tribe_events_pre_get_posts-not-honored-via-ajax\/","name":"Query modifications with tribe_events_pre_get_posts not honored via AJAX -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2015-08-03T18:33:26+00:00","dateModified":"2015-08-04T14:40:46+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/query-modifications-with-tribe_events_pre_get_posts-not-honored-via-ajax\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/query-modifications-with-tribe_events_pre_get_posts-not-honored-via-ajax\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/query-modifications-with-tribe_events_pre_get_posts-not-honored-via-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":"Query modifications with tribe_events_pre_get_posts not honored via 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\/992821","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\/992821\/revisions"}],"predecessor-version":[{"id":992892,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/992821\/revisions\/992892"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=992821"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}