Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Quick example of adding a custom filter
- * A simple copy and paste of the existing Category filter
- * Refer to the last line for how it adds itself to the interface
- * Find this new filter in: WP Admin > Events > Settings > Filterbar
- * Docs for TribeEventsFilter: http://docs.tri.be/Filter-Bar/class-TribeEventsFilter.html
- */
- class TribeEventsFilter_Custom extends TribeEventsFilter {
- public $type = 'checkbox';
- protected function get_values() {
- /** @var wpdb $wpdb */
- global $wpdb;
- // get venue IDs associated with published posts
- $cities = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT m.meta_value FROM {$wpdb->postmeta} m WHERE m.meta_key='_VenueCity'", TribeEvents::POSTTYPE));
- $cities = array_filter($cities);
- if ( empty($cities) ) {
- return array();
- }
- $cities_array = array();
- foreach( $cities as $city ) {
- if($city != ''){
- $cities_array[] = array(
- 'name' => $city,
- 'value' => $city,
- );
- }
- }
- function querySort ($x, $y) {
- return strcasecmp($x['name'], $y['name']);
- }
- usort($cities_array, 'querySort');
- return $cities_array;
- }
- protected function setup_query_args() {
- /*$this->queryArgs = array( 'meta_query' => array( array(
- 'key' => '_VenueCity',
- 'value' => 'Rotterdam',
- ) ) );*/
- }
- }
- // This adds our new filter to the Filterbar options
- // Invokes TribeEventsFilter::__construct($name, $slug);
- $taxonomy_example = new TribeEventsFilter_Custom('Plaats', 'city');
Advertisement
Add Comment
Please, Sign In to add comment