{"id":937242,"date":"2015-01-24T21:42:56","date_gmt":"2015-01-25T05:42:56","guid":{"rendered":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-bar-custom-taxonomy-almost-works\/"},"modified":"2015-01-29T15:36:20","modified_gmt":"2015-01-29T23:36:20","slug":"filter-bar-custom-taxonomy-almost-works","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-bar-custom-taxonomy-almost-works\/","title":{"rendered":"Filter Bar -&gt; custom taxonomy almost works"},"content":{"rendered":"<p>I used a code snippet that was posted earlier and put that in my functions file after I created a custom taxonomy for my events. The taxonomy is called &#8220;division&#8221; and shows up on the event and the filter bar. On it&#8217;s own it filters the events and works fine. If I select a &#8220;division&#8221; and venue it filters properly too. However if I select a category option and &#8220;division&#8221; option (custom taxonomy) filtering no longer works properly and it just combines the results. If I have 2 events, 1 is in the men&#8217;s division and 1 is in the females division and both are under the category &#8220;professional&#8221;, I should be able to select &#8220;professional&#8221; from the category and &#8220;men&#8217;s&#8221; from the custom taxonomy to display one result. Unfortunately this displays both events :(. If I uncheck the professional category it will just display the men&#8217;s custom option I have selected. So on it&#8217;s own it works. Here is the code I&#8217;m using. I feel like there should be fairly simple solution. Thanks for the help.<\/p>\n<p>\/**<br \/>\n* Quick example of adding a custom filter<br \/>\n* A simple copy and paste of the existing Category filter<br \/>\n* Refer to the last line for how it adds itself to the interface<br \/>\n* Find this new filter in: WP Admin &gt; Events &gt; Settings &gt; Filterbar<br \/>\n* Docs for TribeEventsFilter: http:\/\/docs.tri.be\/Filter-Bar\/class-TribeEventsFilter.html<br \/>\n*\/<br \/>\nclass TribeEventsFilter_Custom extends TribeEventsFilter {<br \/>\npublic $type = &#8216;select&#8217;;<\/p>\n<p>public function get_admin_form() {<br \/>\n$title = $this-&gt;get_title_field();<br \/>\n$type = $this-&gt;get_type_field();<br \/>\nreturn $title.$type;<br \/>\n}<\/p>\n<p>protected function get_type_field() {<br \/>\n$name = $this-&gt;get_admin_field_name(&#8216;type&#8217;);<br \/>\n$field = sprintf( __( &#8216;Type: %s %s&#8217;, &#8216;tribe-events-filter-view&#8217; ),<br \/>\nsprintf( &#8216;&lt;label&gt;&lt;input type=&#8221;radio&#8221; name=&#8221;%s&#8221; value=&#8221;select&#8221; %s \/&gt; %s&lt;\/label&gt;&#8217;,<br \/>\n$name,<br \/>\nchecked( $this-&gt;type, &#8216;select&#8217;, false ),<br \/>\n__( &#8216;Dropdown&#8217;, &#8216;tribe-events-filter-view&#8217; )<br \/>\n),<br \/>\nsprintf( &#8216;&lt;label&gt;&lt;input type=&#8221;radio&#8221; name=&#8221;%s&#8221; value=&#8221;checkbox&#8221; %s \/&gt; %s&lt;\/label&gt;&#8217;,<br \/>\n$name,<br \/>\nchecked( $this-&gt;type, &#8216;checkbox&#8217;, false ),<br \/>\n__( &#8216;Checkboxes&#8217;, &#8216;tribe-events-filter-view&#8217; )<br \/>\n)<br \/>\n);<br \/>\nreturn &#8216;&lt;div class=&#8221;tribe_events_active_filter_type_options&#8221;&gt;&#8217;.$field.'&lt;\/div&gt;&#8217;;<br \/>\n}<\/p>\n<p>protected function get_values() {<br \/>\n$event_categories = array();<br \/>\n$event_categories_term = get_terms( &#8216;division&#8217;, array( &#8216;orderby&#8217; =&gt; &#8216;name&#8217;, &#8216;order&#8217; =&gt; &#8216;DESC&#8217; ) );<br \/>\n$event_categories_by_id = array();<br \/>\nforeach( $event_categories_term as $term ) {<br \/>\n$event_categories_by_id[$term-&gt;term_id] = $term;<br \/>\n}<br \/>\n$event_categories_by_id_reverse = array_reverse( $event_categories_by_id );<br \/>\n$parents = array( &#8216;0&#8217; );<br \/>\nwhile ( !empty( $parents ) ) {<br \/>\n$parents_copy = $parents;<br \/>\nforeach ( $event_categories_by_id_reverse as $term ) {<br \/>\nif ( in_array( $term-&gt;parent, $parents_copy ) ) {<br \/>\n$parents[] = $term-&gt;term_id;<br \/>\nunset( $event_categories_by_id[$term-&gt;term_id] );<br \/>\n$event_categories_by_id = TribeEvents::array_insert_after_key( $term-&gt;parent, $event_categories_by_id, array( $term-&gt;term_id =&gt; $term ) );<br \/>\n}<br \/>\n}<br \/>\n$parents = array_diff( $parents, $parents_copy );<br \/>\n}<br \/>\n$child_spacer = &#8216;\u00a0\u00a0&#8216;;<br \/>\nforeach( $event_categories_by_id as $cat ) {<br \/>\n$child_depth = 0;<br \/>\n$parent_id = $cat-&gt;parent;<br \/>\nwhile ( $parent_id != 0 ) {<br \/>\n$child_depth++;<br \/>\n$parent_id = $event_categories_by_id[$parent_id]-&gt;parent;<br \/>\n}<br \/>\n$child_indent = str_repeat($child_spacer, $child_depth);<br \/>\n$event_categories[] = array(<br \/>\n&#8216;name&#8217; =&gt; $child_indent . $cat-&gt;name,<br \/>\n&#8216;value&#8217; =&gt; $cat-&gt;term_id,<br \/>\n&#8216;data&#8217; =&gt; array(<br \/>\n&#8216;slug&#8217; =&gt; $cat-&gt;slug,<br \/>\n),<br \/>\n);<br \/>\n}<br \/>\nreturn $event_categories;<br \/>\n}<\/p>\n<p>protected function setup_query_args() {<br \/>\n$this-&gt;queryArgs = array( &#8216;tax_query&#8217; =&gt; array( array(<br \/>\n&#8216;taxonomy&#8217; =&gt; &#8216;division&#8217;,<br \/>\n&#8216;field&#8217; =&gt; &#8216;id&#8217;,<br \/>\n&#8216;terms&#8217; =&gt; $this-&gt;currentValue,<br \/>\n&#8216;include_children&#8217; =&gt; false,<br \/>\n) ) );<br \/>\n}<\/p>\n<p>}<\/p>\n<p>\/\/ This adds our new filter to the Filterbar options<br \/>\n\/\/ Invokes TribeEventsFilter::__construct($name, $slug);<br \/>\n$taxonomy_example = new TribeEventsFilter_Custom(&#8216;Taxonomy&#8217;, &#8216;taxonomy_filter&#8217;);<\/p>\n","protected":false},"template":"","class_list":["post-937242","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 Bar -&gt; custom taxonomy almost works -<\/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-bar-custom-taxonomy-almost-works\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Filter Bar -&gt; custom taxonomy almost works -\" \/>\n<meta property=\"og:description\" content=\"I used a code snippet that was posted earlier and put that in my functions file after I created a custom taxonomy for my events. The taxonomy is called &#8220;division&#8221; and shows up on the event and the filter bar. On it&#8217;s own it filters the events and works fine. If I select a &#8220;division&#8221; [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-bar-custom-taxonomy-almost-works\/\" \/>\n<meta property=\"article:modified_time\" content=\"2015-01-29T23:36:20+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=\"3 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\/filter-bar-custom-taxonomy-almost-works\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-bar-custom-taxonomy-almost-works\/\",\"name\":\"Filter Bar -&gt; custom taxonomy almost works -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2015-01-25T05:42:56+00:00\",\"dateModified\":\"2015-01-29T23:36:20+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-bar-custom-taxonomy-almost-works\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-bar-custom-taxonomy-almost-works\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-bar-custom-taxonomy-almost-works\/#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\":\"Filter Bar\",\"item\":\"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/filter-bar\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Filter Bar -&gt; custom taxonomy almost works\"}]},{\"@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 Bar -&gt; custom taxonomy almost works -","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-bar-custom-taxonomy-almost-works\/","og_locale":"en_US","og_type":"article","og_title":"Filter Bar -&gt; custom taxonomy almost works -","og_description":"I used a code snippet that was posted earlier and put that in my functions file after I created a custom taxonomy for my events. The taxonomy is called &#8220;division&#8221; and shows up on the event and the filter bar. On it&#8217;s own it filters the events and works fine. If I select a &#8220;division&#8221; [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-bar-custom-taxonomy-almost-works\/","article_modified_time":"2015-01-29T23:36:20+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-bar-custom-taxonomy-almost-works\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-bar-custom-taxonomy-almost-works\/","name":"Filter Bar -&gt; custom taxonomy almost works -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2015-01-25T05:42:56+00:00","dateModified":"2015-01-29T23:36:20+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-bar-custom-taxonomy-almost-works\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-bar-custom-taxonomy-almost-works\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/filter-bar-custom-taxonomy-almost-works\/#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":"Filter Bar","item":"https:\/\/theeventscalendar.com\/support\/forums\/forum\/events\/filter-bar\/"},{"@type":"ListItem","position":5,"name":"Filter Bar -&gt; custom taxonomy almost works"}]},{"@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\/937242","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":2,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/937242\/revisions"}],"predecessor-version":[{"id":937660,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/937242\/revisions\/937660"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=937242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}