ok, here is the solution I used. Users can search for locations name, address and town:
in classes/em-locations.php, I added two functions:
function search_locations($q){
global $wpdb;
$q = rawurldecode($q);
$results = array();
$location_cond = (is_user_logged_in() && !current_user_can('read_others_locations')) ? "AND location_owner=".get_current_user_id() : '';
if( !is_user_logged_in() && get_option('dbem_events_anonymous_submissions') ){
if( !user_can(get_option('dbem_events_anonymous_user'),'read_private_locations') ){
$location_cond = " AND location_private=0";
}
}elseif( is_user_logged_in() && !current_user_can('read_private_locations') ){
$location_cond = " AND location_private=0";
}elseif( !is_user_logged_in() ){
$location_cond = " AND location_private=0";
}
$term = (isset($_REQUEST['term'])) ? '%'.$_REQUEST['term'].'%' : '%'.$q.'%';
$sql = $wpdb->prepare("
SELECT
location_id AS <code>id</code>,
Concat( location_name ) AS <code>label</code>,
location_name AS <code>value</code>,
location_address AS <code>address</code>,
location_town AS <code>town</code>,
location_state AS <code>state</code>,
location_region AS <code>region</code>,
location_postcode AS <code>postcode</code>,
location_country AS <code>country</code>,
location_slug AS <code>slug</code>
FROM ".EM_LOCATIONS_TABLE."
WHERE ( <code>location_name</code> LIKE %s || <code>location_address</code> LIKE %s || <code>location_town</code> LIKE %s) AND location_status=1 $location_cond LIMIT 30
", $term, $term, $term);
$results_obj = $wpdb->get_results($sql);
// convert results from object to array type
$results_arr = self::toArray($results_obj);
return $results_arr;
}
// convert results from object to array type
function toArray($obj) {
if(is_object($obj)) $obj = (array) $obj;
if(is_array($obj)) {
$new = array();
foreach($obj as $key => $val) {
$new[$key] = self::toArray($val);
}
}
else {
$new = $obj;
}
return $new;
}
and in templates/templates/locations-list.php, I added the following code:
<form id="locations-dir-search" method="get" action="<?php echo site_url();?>/events/locations/">
<input type="hidden" name="action" value="search_locations" />
search locations <input type="text" id="locations_search" name="q" onblur="if(this.value=='')this.value='venue name, address, city'" onfocus="if(this.value=='venue name, address, city')this.value=''" value="venue name, address, city" />
<input type="submit" value="search" />
</form>
<?php
// if user searchs for location
if( !empty($_REQUEST['action']) && $_REQUEST['action'] == "search_locations" && (!empty($_REQUEST['q'])) ){
//$q = rawurlencode($_REQUEST['q']);
$q = $_REQUEST['q'];
//print_r('<pre>');print_r( EM_Locations::search_locations($q) ); print_r('</pre>');
$locations = EM_Locations::search_locations($q);
if(!empty($locations))
{
for($i=0; $i<count($locations); $i++) {
echo '<a href="'.site_url().'/events/locations/'.$locations[$i]['slug'].'">'.$locations[$i]['value'] . '</a> ' . $locations[$i]['address'] . '<br/>';
}
}else{
echo 'No Locations';
}
}else { // display default results of location list
echo EM_Locations::output(apply_filters('em_content_locations_args', $args));
}
Although, I didn’t have time to include the pagination feature that’s included in the EM_Locations:output function, and I simply limited the results to 30. Perhaps someone will have the time to post solution here