Add a custom field in the search form on the event dashboard

Add a custom field in the search form on the event dashboard

In order to add customize search filters to the event dashboard, please enter the following code in the functions.php file:

  1. add_action('event_manager_event_dashboard_event_filter_start', 'my_theme_custom_filter');
  2. function my_theme_custom_filter()
  3. { ?>
  4.     <div class="wpem-events-filter-block">
  5.         <?php $search_location = isset($_GET['search_location']) ? $_GET['search_location'] : ''; ?>        <div class="wpem-form-group"><input name="search_location" id="search_location" type="text" value="<?php echo $search_location; ?>" placeholder="<?php _e('Location','wp-event-manager');?>"></div>
        </div>
  6. <?php }
  7. add_filter( 'event_manager_get_dashboard_events_args', 'my_theme_custom_search', 10 );
  8. function my_theme_custom_search($args)
  9. {
  10.     if( isset($_GET['search_location']) && !empty($_GET['search_location']) )
  11.     {
  12.         $location_meta_keys = array( 'geolocation_formatted_address', '_event_location', 'geolocation_state_long' );
  13.         $location_search    = array( 'relation' => 'OR' );
  14.         foreach ( $location_meta_keys as $meta_key ) {
  15.             $location_search[] = array(
  16.                 'key'     => $meta_key,
  17.                 'value'   => $_GET['search_location'],
  18.                 'compare' => 'like'
  19.             );
  20.         }
  21.         $args['meta_query'][] = $location_search;
  22.     }
  23.     return $args;
  24. }