jmccole83
3/7/2019 - 4:59 PM

Custom Event Filter

@php

$filters     = tribe_events_get_filters();
$views       = tribe_events_get_views();
$current_url = tribe_events_get_current_filter_url();
$classes     = array( 'tribe-clearfix' );

if ( ! empty( $filters ) ) {
	$classes[] = 'tribe-events-bar--has-filters';
}

if ( count( $views ) > 1 ) {
	$classes[] = 'tribe-events-bar--has-views';
}

$terms = get_terms(
	Tribe__Events__Main::TAXONOMY, array(
    'hide_empty'    => 0,
    'parent'        => 0,
    'orderby'       => 'name',
    'order'         => 'ASC',
    'hierarchical'  => true
	)
);

@endphp

<div id="tribe-events-bar" class="sidebar-search">

	<h2>Event Search</h2>

  <form role="search" action="@php echo site_url('/') @endphp" method="get" id="searchform">

	  <div class="select-wrap">
	    <select name="tribe_events_cat" id="events_cat">
	      <option value="" selected="true" disabled>Select Event Type</option>
					@foreach ( $terms as $term )
	        <option value="{!! $term->slug !!}">
						{!! $term->name !!}
	        </option>
					@endforeach
	    </select>
	  </div>
	  <div class="select-wrap">
	    <select name="tribe-bar-date" id="bar-date">
	      <option value="" selected="true" disabled>Select Event Date</option>
				@foreach ( $event_months as $month )
        <option value="{!! $month[0] !!}">
					{!! $month[0] !!}
        </option>
				@endforeach
	    </select>
	  </div>

		<input type="hidden" name="post_type" value="tribe_events" /> <!-- // hidden 'tribe_events' value -->

	  <div class="tribe-bar-submit">
	    <input class="tribe-events-button tribe-no-param" type="submit" name="submit-bar" aria-label="@php printf( esc_attr__( 'Submit %s search', 'the-events-calendar' ), tribe_get_event_label_plural() ) @endphp" value="@php printf( esc_attr__( 'Search', 'the-events-calendar' ), tribe_get_event_label_plural() ) @endphp" />
	  </div>

	</form>

</div>
// Events Month search
public function event_months()
{
  global $wpdb;

  $event_months = $wpdb->get_results( "SELECT DATE_FORMAT(meta_value, '%b %Y') as event_date
  FROM $wpdb->postmeta
  WHERE meta_key = '_EventStartDate'
  GROUP BY event_date
  ORDER BY meta_value", ARRAY_N);

  return $event_months;
}