AjaxSearchPro Events Manager. Double location towns

Home Forums Product Support Forums Ajax Search Pro for WordPress Support AjaxSearchPro Events Manager. Double location towns

This topic contains 22 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 3 years, 3 months ago.

Viewing 8 posts - 16 through 23 (of 23 total)
  • Author
    Posts
  • #23587
    mar1eke_louise
    mar1eke_louise
    Participant

    Hi Ernest,

    Thank you for your reply, it could also be a country restrict, my IP changes and I never have problems loggin in. When you use Filezilla, is logon type set to normal?

    Can I please get your IP and the country you are in so they can whitelist either your ip or the country, that should do the trick.

    This code did not work, it threw a 500 error so I have put it back for now.

    Thank you again,
    Marieke

    #23588
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #23589
    mar1eke_louise
    mar1eke_louise
    Participant
    You cannot access this content.
    #23607
    Ernest Marcinko
    Ernest 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;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #23615
    mar1eke_louise
    mar1eke_louise
    Participant

    You are a star!!

    Thank you for your time and helping out with this.

    Have a nice weekend.
    Marieke

    #23616
    Ernest Marcinko
    Ernest Marcinko
    Keymaster
    You cannot access this content. Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #23799
    mar1eke_louise
    mar1eke_louise
    Participant

    Hi Ernest,

    It is me again!

    All is working as initially requested by the client, but as you might know, a client can change their mind and it does have to do with this code. In all other options there is a possibilty to add ALL option, this is not the case with this custom code and the client wants this option back to show all events in all locations first. The location starts with the first location, Arnhem, and shows only the events in Arnhem and only changes that when you select another location.

    Could you have a nother look to see if it is possible to add the ||Any value** back in this code?

    Thank you,
    Marieke

    #23809
    Ernest Marcinko
    Ernest Marcinko
    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;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 8 posts - 16 through 23 (of 23 total)

You must be logged in to reply to this topic.