{"id":1250350,"date":"2017-03-07T03:49:46","date_gmt":"2017-03-07T11:49:46","guid":{"rendered":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-filter-to-events-page\/"},"modified":"2017-03-07T03:49:46","modified_gmt":"2017-03-07T11:49:46","slug":"custom-filter-to-events-page","status":"closed","type":"topic","link":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-filter-to-events-page\/","title":{"rendered":"Custom filter to events page"},"content":{"rendered":"<p>Hello ,<\/p>\n<p>I would like to add Zip code filter to events page : http:\/\/freshatx.wpengine.com\/events\/<\/p>\n<p>I would like to add filter of Venue Zip codes list in this filter.<\/p>\n<p>I have add the following code to my theme functions file, filter display fine at admin end as well as in front end as you can see in the above URL.<\/p>\n<p>But this is not returning results, please let me know how can I set function setup_query_args() arguments so that it will return correct results.<\/p>\n<p>Following is my code :<\/p>\n<p>\/\/Add zIP Filters to events page<br \/>\nclass TribeEventsFilter_ZipCode extends TribeEventsFilter {<br \/>\n  public $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 \/>\n    return $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 \/>\n      sprintf( &#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 \/>\n        checked( $this-&gt;type, &#8216;select&#8217;, false ),<br \/>\n        __( &#8216;Dropdown&#8217;, &#8216;tribe-events-filter-view&#8217; )<br \/>\n      ),<br \/>\n      sprintf( &#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 \/>\n        checked( $this-&gt;type, &#8216;checkbox&#8217;, false ),<br \/>\n        __( &#8216;Checkboxes&#8217;, &#8216;tribe-events-filter-view&#8217; )<br \/>\n      )<br \/>\n    );<br \/>\n    return &#8216;&lt;div class=&#8221;tribe_events_active_filter_type_options&#8221;&gt;&#8217;.$field.'&lt;\/div&gt;&#8217;;<br \/>\n  }<\/p>\n<p>\t\/\/ function to grab all possible meta values of the chosen meta key.<br \/>\n\tprotected function get_values() {<\/p>\n<p>\t\t$posts = get_posts(<br \/>\n\t\t\tarray(<br \/>\n\t\t\t\t&#8216;post_type&#8217; =&gt; &#8216;tribe_venue&#8217;,<br \/>\n\t\t\t\t&#8216;meta_key&#8217; =&gt; &#8216;_VenueZip&#8217;,<br \/>\n\t\t\t\t&#8216;posts_per_page&#8217; =&gt; -1,<br \/>\n\t\t\t)<br \/>\n\t\t);<\/p>\n<p>\t\t$meta_values = array();<\/p>\n<p>\t\tforeach( $posts as $post ) {<\/p>\n<p>\t\t\t$meta_value = get_post_meta( $post-&gt;ID, &#8216;_VenueZip&#8217;, true );<br \/>\n\t\t\tif($meta_value !=&#8221;){<br \/>\n\t\t\t  $meta_values[] = array(<br \/>\n\t\t\t\t&#8216;name&#8217; =&gt; $meta_value,<br \/>\n\t\t\t\t&#8216;value&#8217; =&gt; $meta_value,<\/p>\n<p>\t\t\t  );<br \/>\n\t\t\t}<br \/>\n\t\t}<\/p>\n<p>\t\treturn $meta_values;<\/p>\n<p>\t}<br \/>\n\tprotected function setup_query_args() {<\/p>\n<p>\t\t$this-&gt;queryArgs = array(<\/p>\n<p>\t\t\t&#8216;post_type&#8217; \t=&gt; &#8216;tribe_events&#8217;,<br \/>\n\t\t\t&#8216;meta_key&#8217;\t\t=&gt; &#8216;_VenueZip&#8217;,<br \/>\n\t\t\t&#8216;meta_value&#8217; =&gt; &#8216;value&#8217;,<br \/>\n\t\t\t&#8216;meta_value_num&#8217; =&gt; $this-&gt;currentValue,<br \/>\n\t\t\t&#8216;meta_compare&#8217; \t=&gt; &#8216;LIKE&#8217;,<br \/>\n\t\t);<br \/>\n\t}<\/p>\n<p>}<br \/>\n\/\/ This adds our new filter to the Filterbar options<br \/>\n\/\/ Invokes TribeEventsFilter::__construct($name, $slug);<br \/>\nfunction ZipCode_taxfilter(){<br \/>\n  new TribeEventsFilter_ZipCode(&#8216;ZipCode&#8217;, &#8216;zipcode&#8217;);<br \/>\n}<br \/>\nadd_action(&#8216;tribe_events_filters_create_filters&#8217;,&#8217;ZipCode_taxfilter&#8217;);<\/p>\n<p>Thanks.<\/p>\n","protected":false},"template":"","class_list":["post-1250350","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>Custom filter to events page -<\/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\/custom-filter-to-events-page\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Custom filter to events page -\" \/>\n<meta property=\"og:description\" content=\"Hello , I would like to add Zip code filter to events page : http:\/\/freshatx.wpengine.com\/events\/ I would like to add filter of Venue Zip codes list in this filter. I have add the following code to my theme functions file, filter display fine at admin end as well as in front end as you can [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-filter-to-events-page\/\" \/>\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\/custom-filter-to-events-page\/\",\"url\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-filter-to-events-page\/\",\"name\":\"Custom filter to events page -\",\"isPartOf\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/#website\"},\"datePublished\":\"2017-03-07T11:49:46+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-filter-to-events-page\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-filter-to-events-page\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-filter-to-events-page\/#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\":\"Custom filter to events page\"}]},{\"@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":"Custom filter to events page -","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\/custom-filter-to-events-page\/","og_locale":"en_US","og_type":"article","og_title":"Custom filter to events page -","og_description":"Hello , I would like to add Zip code filter to events page : http:\/\/freshatx.wpengine.com\/events\/ I would like to add filter of Venue Zip codes list in this filter. I have add the following code to my theme functions file, filter display fine at admin end as well as in front end as you can [&hellip;]","og_url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-filter-to-events-page\/","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\/custom-filter-to-events-page\/","url":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-filter-to-events-page\/","name":"Custom filter to events page -","isPartOf":{"@id":"https:\/\/theeventscalendar.com\/support\/#website"},"datePublished":"2017-03-07T11:49:46+00:00","breadcrumb":{"@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-filter-to-events-page\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-filter-to-events-page\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/theeventscalendar.com\/support\/forums\/topic\/custom-filter-to-events-page\/#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":"Custom filter to events page"}]},{"@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\/1250350","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":0,"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/topic\/1250350\/revisions"}],"wp:attachment":[{"href":"https:\/\/theeventscalendar.com\/support\/wp-json\/wp\/v2\/media?parent=1250350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}