This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: AjaxSearchPro Events Manager. Double location towns

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

#23607
Ernest MarcinkoErnest Marcinko
Keymaster

Thank you, that helped.

So, I found the error in the code, and I corrected it, you will find the working version below. I also made an adjustment to the filter, like so: https://i.imgur.com/N2U0AYz.png
Since those are numeri values, and there is a possibility of multiple values, I changed the inner logic to ‘OR’ as you see.

With this combination, it should merge the town names, and show the results matching those meta values.

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();
        foreach ( $filter->get() as $kk=>$item ) {
          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;
            }
          }
          ksort($locarr);
          foreach ( $locarr as $key => $loc ) {
            if ( !empty($key) && !empty($loc) )
              $filter->add(array(
                'value' => $loc,
                'label' => $key,
              ));
          }
        }
        $filters[$k] = $filter;
      }
	}
  }
  
  return $filters;
}