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

#23101
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

Okay, I see where the problem is. The matching location names all have different IDs, despite the same names, that’s why the code has no effect. I have made an addition to the existing code, that may resolve that. As of the previous version, the plugin supports multiple values per drop-dow, when separated by double dots, such as:

value1::value2::value3||Option

Where either of the values can be matched. Based on that, I would try this solution. Be careful, as I did not test this solution, you might have to make adjustments to it:

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;
        }
        $item->asp_f_dropdown_value[] = array(
            $loc->location_id, $loc->location_town
        );
      }
      ksort($locarr);
      foreach ( $locarr as $key => $loc ) {
        $item->asp_f_dropdown_value[] = array(
            $loc, $key
        );
      }
    }
  }
  return $item;
}