{"id":1272009,"date":"2017-04-20T01:40:48","date_gmt":"2017-04-20T08:40:48","guid":{"rendered":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/exclude-events-category-from-all-queries-but-not-for-admins\/"},"modified":"2017-04-22T11:55:05","modified_gmt":"2017-04-22T18:55:05","slug":"exclude-events-category-from-all-queries-but-not-for-admins","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/exclude-events-category-from-all-queries-but-not-for-admins\/","title":{"rendered":"Exclude Events Category from all queries (but not for admins)"},"content":{"rendered":"<p>Dear Support Team,<\/p>\n<p>awhile ago I started <a href=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/adjust-ajax-search-to-exclude-event-taxonomy\/\" target=\"_blank\">a thread asking to exclude a certain category<\/a> from all queries, but not for the administrator. I had found several topics but the snippets posted there did not seem to work for me: Whenever I used the list-view widget (TEC pro), all filters, even those set by the widget, were removed.<\/p>\n<p>I have now managed to create a function that filters a specific category on all queries:<\/p>\n<pre><code>function tribe_exclude_events_category( $wp_query ) {\r\n\/\/ only filter the query if the user cannot edit pages (&lt; editor)\r\n\t\t if (!current_user_can('edit_pages')) {\r\n\t\t\t$exclude_cats = array('exclude-me'); \r\n\r\n\t\t\t\/\/ Join with current tax query if set\r\n\t\t\tif (is_array($wp_query-&gt;get( 'tax_query')))\r\n\t\t\t\t{$tax_query =$wp_query-&gt;get( 'tax_query');}\r\n\t\t\telse\r\n\t\t\t\t{$tax_query = array();}\r\n\r\n\t\t\t\/\/ Setup an exclude from the tribe_events_cat taxonomy\r\n\t\t\t$tax_query[] = array(\r\n\t\t\t\t'taxonomy'  =&gt; Tribe__Events__Main::TAXONOMY,   \/\/ sidebar ist: \"tribe_events_cat\"\r\n\t\t\t\t'field'     =&gt; 'slug',\r\n\t\t\t\t'terms'     =&gt; $exclude_cats,\r\n\t\t\t\t'operator'  =&gt; 'NOT IN'\r\n\t\t\t);\r\n\r\n\t\t\t$wp_query-&gt;set('tax_query', $tax_query);\r\n\t\t}\r\n\r\n\t\treturn $wp_query;\r\n}\r\n\r\nadd_action( 'pre_get_posts', 'tribe_exclude_events_category', 10, 1 );<\/code><\/pre>\n<p>This is basically the code from <a href=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/exclude-category-the-events-calendar-not-pro\/\" target=\"_blank\">this topic<\/a> with a couple of changes. The most significant is, that the wrong tax_query was selected by the snippet in the other thread:<br \/>\nIt must be <code>$wp_query-&gt;get( 'tax_query')<\/code> instead of <code>$wp_query-&gt;tax_query<\/code><\/p>\n<p>I just wanted to share this with the TEC community &#8211; maybe it will be helpful for others in the future.<\/p>\n<p>Happy coding, everyone!<\/p>\n","protected":false},"template":"","class_list":["post-1272009","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>Exclude Events Category from all queries (but not for admins) -<\/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\/exclude-events-category-from-all-queries-but-not-for-admins\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Exclude Events Category from all queries (but not for admins) -\" \/>\n<meta property=\"og:description\" content=\"Dear Support Team, awhile ago I started a thread asking to exclude a certain category from all queries, but not for the administrator. I had found several topics but the snippets posted there did not seem to work for me: Whenever I used the list-view widget (TEC pro), all filters, even those set by the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/exclude-events-category-from-all-queries-but-not-for-admins\/\" \/>\n<meta property=\"article:modified_time\" content=\"2017-04-22T18:55:05+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\/exclude-events-category-from-all-queries-but-not-for-admins\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/exclude-events-category-from-all-queries-but-not-for-admins\/\",\"name\":\"Exclude Events Category from all queries (but not for admins) -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2017-04-20T08:40:48+00:00\",\"dateModified\":\"2017-04-22T18:55:05+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/exclude-events-category-from-all-queries-but-not-for-admins\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/exclude-events-category-from-all-queries-but-not-for-admins\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/exclude-events-category-from-all-queries-but-not-for-admins\/#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\":\"Exclude Events Category from all queries (but not for admins)\"}]},{\"@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":"Exclude Events Category from all queries (but not for admins) -","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\/exclude-events-category-from-all-queries-but-not-for-admins\/","og_locale":"en_US","og_type":"article","og_title":"Exclude Events Category from all queries (but not for admins) -","og_description":"Dear Support Team, awhile ago I started a thread asking to exclude a certain category from all queries, but not for the administrator. I had found several topics but the snippets posted there did not seem to work for me: Whenever I used the list-view widget (TEC pro), all filters, even those set by the [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/exclude-events-category-from-all-queries-but-not-for-admins\/","article_modified_time":"2017-04-22T18:55:05+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\/exclude-events-category-from-all-queries-but-not-for-admins\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/exclude-events-category-from-all-queries-but-not-for-admins\/","name":"Exclude Events Category from all queries (but not for admins) -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2017-04-20T08:40:48+00:00","dateModified":"2017-04-22T18:55:05+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/exclude-events-category-from-all-queries-but-not-for-admins\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/exclude-events-category-from-all-queries-but-not-for-admins\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/exclude-events-category-from-all-queries-but-not-for-admins\/#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":"Exclude Events Category from all queries (but not for admins)"}]},{"@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\/1272009","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\/1272009\/revisions"}],"predecessor-version":[{"id":1273136,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1272009\/revisions\/1273136"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=1272009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}