Forum Replies Created
-
AuthorPosts
-
Chris Fleming
ParticipantBarry, seems the the last piece to the puzzle is adding “tribe_events_pre_get_posts” filter correctly. I set this up as suggested and posted the code. Should I be adding this to the extended class, I haven’t had luck with that. Help getting this last piece setup would be great. Seems this would also put an end to all the questions everyone is asking on the same issue.
Side Note: When are the additional fields going to be added to the filter bar add-on? I see this was mentioned almost a year ago but there hasn’t been any news. The same goes for adding documentation for the custom taxonomy filter development. At least if the last piece to the puzzle (query output) is resolved you would have working code to give to people.
Chris Fleming
ParticipantWhere should I run this? In the class doesn’t seem to change the query?
function my_search_filter() { $taxquery = array( array( 'taxonomy' => 'format', 'field' => 'id', 'terms' => $this->currentValue, 'include_children' => false, ) ); $query->set( 'tax_query', $taxquery ); return $query; } add_filter( 'tribe_events_pre_get_posts', $query );Chris Fleming
ParticipantThanks I will give this a shot and let you know what happens. I found a support question and used some info from that but I can’t seem to find it now :/ Originally it ended with this:
new TribeEventsFilter_Format('Format', 'format');This worked as a filter on its own but not with the original event filter so I had to change it to this:
function Format_taxfilter(){ new TribeEventsFilter_format('Format', 'format'); } add_action('tribe_events_filters_create_filters','Format_taxfilter');This allowed one filter to work properly and play nice with the other filters. But I guess there was only room for 1 new friend at that party.
Chris Fleming
ParticipantI was able to fix that but if I add 2 custom taxonomies for filters now they conflict with one another :/
/** * Add custom FILTER ("division") - Men's / Women's / Coed / Rev-Coed */ /** * A simple copy and paste of the existing Category filter * Find this new filter in: WP Admin > Events > Settings > Filterbar * Docs for TribeEventsFilter: http://docs.tri.be/Filter-Bar/class-TribeEventsFilter.html */ class TribeEventsFilter_CustomClubs extends TribeEventsFilter { public $type = 'dropdown'; public function get_admin_form() { $title = $this->get_title_field(); $type = $this->get_type_field(); return $title.$type; } protected function get_type_field() { $name = $this->get_admin_field_name('type'); $field = sprintf( __( 'Type: %s %s', 'tribe-events-filter-view' ), sprintf( '<label><input type="radio" name="%s" value="select" %s /> %s</label>', $name, checked( $this->type, 'select', false ), __( 'Dropdown', 'tribe-events-filter-view' ) ), sprintf( '<label><input type="radio" name="%s" value="checkbox" %s /> %s</label>', $name, checked( $this->type, 'checkbox', false ), __( 'Checkboxes', 'tribe-events-filter-view' ) ) ); return '<div class="tribe_events_active_filter_type_options">'.$field.'</div>'; } protected function get_values() { $event_clubs = array(); $event_clubs_term = get_terms( 'division', array( 'orderby' => 'name', 'order' => 'DESC' ) ); $event_clubs_by_id = array(); foreach( $event_clubs_term as $term ) { $event_clubs_by_id[$term->term_id] = $term; } $event_clubs_by_id_reverse = array_reverse( $event_clubs_by_id ); $parents = array( '0' ); while ( !empty( $parents ) ) { $parents_copy = $parents; foreach ( $event_clubs_by_id_reverse as $term ) { if ( in_array( $term->parent, $parents_copy ) ) { $parents[] = $term->term_id; unset( $event_clubs_by_id[$term->term_id] ); $event_clubs_by_id = TribeEvents::array_insert_after_key( $term->parent, $event_clubs_by_id, array( $term->term_id => $term ) ); } } $parents = array_diff( $parents, $parents_copy ); } $child_spacer = ' '; foreach( $event_clubs_by_id as $cat ) { $child_depth = 0; $parent_id = $cat->parent; while ( $parent_id != 0 ) { $child_depth++; $parent_id = $event_clubs_by_id[$parent_id]->parent; } $child_indent = str_repeat($child_spacer, $child_depth); $event_clubs[] = array( 'name' => $child_indent . $cat->name, 'value' => $cat->term_id, 'data' => array( 'slug' => $cat->slug, ), ); } return $event_clubs; } protected function setup_query_args() { $this->queryArgs = array( 'tax_query' => array( array( 'taxonomy' => 'division', 'field' => 'id', 'terms' => $this->currentValue, 'include_children' => false, ) ) ); } } // This adds our new filter to the Filterbar options // Invokes TribeEventsFilter::__construct($name, $slug); function CustomClubs_taxfilter(){ new TribeEventsFilter_CustomClubs('Division', 'division'); } add_action('tribe_events_filters_create_filters','CustomClubs_taxfilter'); /** * Add custom FILTER ("format") - 2's / 4's / 6's */ /** * A simple copy and paste of the existing Category filter * Find this new filter in: WP Admin > Events > Settings > Filterbar * Docs for TribeEventsFilter: http://docs.tri.be/Filter-Bar/class-TribeEventsFilter.html */ class TribeEventsFilter_format extends TribeEventsFilter { public $type = 'select'; public function get_admin_form() { $title = $this->get_title_field(); $type = $this->get_type_field(); return $title.$type; } protected function get_type_field() { $name = $this->get_admin_field_name('type'); $field = sprintf( __( 'Type: %s %s', 'tribe-events-filter-view' ), sprintf( '<label><input type="radio" name="%s" value="select" %s /> %s</label>', $name, checked( $this->type, 'select', false ), __( 'Dropdown', 'tribe-events-filter-view' ) ), sprintf( '<label><input type="radio" name="%s" value="checkbox" %s /> %s</label>', $name, checked( $this->type, 'checkbox', false ), __( 'Checkboxes', 'tribe-events-filter-view' ) ) ); return '<div class="tribe_events_active_filter_type_options">'.$field.'</div>'; } protected function get_values() { $event_format = array(); $event_format_term = get_terms( 'format', array( 'orderby' => 'name', 'order' => 'DESC' ) ); $event_format_by_id = array(); foreach( $event_format_term as $term ) { $event_format_by_id[$term->term_id] = $term; } $event_format_by_id_reverse = array_reverse( $event_format_by_id ); $parents = array( '0' ); while ( !empty( $parents ) ) { $parents_copy = $parents; foreach ( $event_format_by_id_reverse as $term ) { if ( in_array( $term->parent, $parents_copy ) ) { $parents[] = $term->term_id; unset( $event_format_by_id[$term->term_id] ); $event_format_by_id = TribeEvents::array_insert_after_key( $term->parent, $event_format_by_id, array( $term->term_id => $term ) ); } } $parents = array_diff( $parents, $parents_copy ); } $child_spacer = ' '; foreach( $event_format_by_id as $cat ) { $child_depth = 0; $parent_id = $cat->parent; while ( $parent_id != 0 ) { $child_depth++; $parent_id = $event_format_by_id[$parent_id]->parent; } $child_indent = str_repeat($child_spacer, $child_depth); $event_format[] = array( 'name' => $child_indent . $cat->name, 'value' => $cat->term_id, 'data' => array( 'slug' => $cat->slug, ), ); } return $event_format; } protected function setup_query_args() { $this->queryArgs = array( 'tax_query' => array( array( 'taxonomy' => 'format', 'field' => 'id', 'terms' => $this->currentValue, 'include_children' => false, ) ) ); } } // This adds our new filter to the Filterbar options // Invokes TribeEventsFilter::__construct($name, $slug); function Format_taxfilter(){ new TribeEventsFilter_format('Format', 'format'); } add_action('tribe_events_filters_create_filters','Format_taxfilter'); -
AuthorPosts
