Guest User

Untitled

a guest
Dec 11th, 2014
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.49 KB | None | 0 0
  1. /**
  2.  * Quick example of adding a custom filter
  3.  * A simple copy and paste of the existing Category filter
  4.  * Refer to the last line for how it adds itself to the interface
  5.  * Find this new filter in: WP Admin > Events > Settings > Filterbar
  6.  * Docs for TribeEventsFilter: http://docs.tri.be/Filter-Bar/class-TribeEventsFilter.html
  7.  */
  8. class TribeEventsFilter_Custom extends TribeEventsFilter {
  9.     public $type = 'checkbox';
  10.  
  11.     protected function get_values() {
  12.         /** @var wpdb $wpdb */
  13.         global $wpdb;
  14.  
  15.         // get venue IDs associated with published posts
  16.         $cities = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT m.meta_value FROM {$wpdb->postmeta} m  WHERE m.meta_key='_VenueCity'", TribeEvents::POSTTYPE));
  17.         $cities = array_filter($cities);
  18.  
  19.        
  20.         if ( empty($cities) ) {
  21.             return array();
  22.         }
  23.         $cities_array = array();
  24.         foreach( $cities as $city ) {
  25.             if($city != ''){
  26.                 $cities_array[] = array(
  27.                     'name' => $city,
  28.                     'value' => $city,
  29.                 );
  30.             }
  31.         }
  32.  
  33.         function querySort ($x, $y) {
  34.             return strcasecmp($x['name'], $y['name']);
  35.         }
  36.  
  37.         usort($cities_array, 'querySort');
  38.  
  39.         return $cities_array;
  40.     }
  41.  
  42.     protected function setup_query_args() {
  43.         /*$this->queryArgs = array( 'meta_query' => array( array(
  44.             'key' => '_VenueCity',
  45.             'value' => 'Rotterdam',
  46.         ) ) );*/
  47.     }
  48.  
  49. }
  50.  
  51.  
  52.  
  53. // This adds our new filter to the Filterbar options
  54. // Invokes TribeEventsFilter::__construct($name, $slug);
  55. $taxonomy_example = new TribeEventsFilter_Custom('Plaats', 'city');
Advertisement
Add Comment
Please, Sign In to add comment