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
June 12, 2019 at 1:31 pm
#23124
Keymaster
Hi,
Well, I am just guessing at this point, but maybe this one:
add_filter('asp_cf_item_view', 'asp_em_locations_cf_filter', 10, 1);
function asp_em_locations_cf_filter($item) {
if ( $item->asp_f_field == '_location_id' && class_exists('EM_Locations') ) {
$location_ids = array();
foreach ( $item->asp_f_dropdown_value as $k=>$v ) {
if ( is_numeric($v[1]) ) {
$location_ids[] = $v[2];
unset($item->asp_f_dropdown_value[$k]);
}
}
$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;
}
}
ksort($locarr);
foreach ( $locarr as $key => $loc ) {
if ( !empty($key) && !empty($loc) )
$item->asp_f_dropdown_value[] = array(
$loc, $key
);
}
}
}
return $item;
}