Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › AjaxSearchPro Events Manager. Double location towns › Reply To: AjaxSearchPro Events Manager. Double location towns
August 28, 2019 at 12:03 pm
#23809
Keymaster
Hi Marieke,
Maybe this variation would consider the “any value” option as well:
add_filter('asp_pre_get_front_filters', 'asp_locations_pre_get_front_filters', 10, 2);
function asp_locations_pre_get_front_filters($filters, $type) {
if ( $type == 'custom_field' ) {
foreach ($filters as $k => $filter) {
if ( $filter->data['field'] == '_location_id' && class_exists('EM_Locations') ) {
$location_ids = array();
$select_all = false;
foreach ( $filter->get() as $kk=>$item ) {
if ( $item->value == '' ) {
$select_all = $item->label;
} else if ( is_numeric($item->value) ) {
$location_ids[] = $item->value;
}
}
$filter->remove();
$locations = EM_Locations::get( array('location'=>array_unique($location_ids)) );
$locarr = array();
if ( is_array($locations) && count($locations) > 0 ) {
foreach ( $locations as $loc ) {
if ( isset($locarr[$loc->location_town]) ) {
$locarr[$loc->location_town] .= '::' . $loc->location_id;
} else {
$locarr[$loc->location_town] = $loc->location_id;
}
}
if ( $select_all !== false ) {
$filter->add(array(
'value' => '',
'label' => $select_all,
));
}
ksort($locarr);
foreach ( $locarr as $key => $loc ) {
if ( !empty($key) && !empty($loc) )
$filter->add(array(
'value' => $loc,
'label' => $key,
));
}
}
$filters[$k] = $filter;
}
}
}
return $filters;
}