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, 1 month ago.

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #23059
    mar1eke_louise
    mar1eke_louise
    Participant

    Hello,

    A client of mine uses AjaxSearchPro in combination with ACF and Events Manager. Everything is set up and working very good, your plugin does exactly was is needed. However I have one question.

    I followed directions in your tutorial to make the locations of the events searchable and it works perfectly. The only thing is, is that if I use location_town in stead of location_name, all the location towns are shown, this is what is needed, what the problem is, is that the town names are shown as double entries, say we have 5 events in location Arnhem, with this code the town Arnhem is shown 5 times in the dropdown. What I would like to achieve is that the town name is only shown 1 time and when a user chooses that town, the 5 events will show up in the search results. I hope you understand what I am looking for. The searchform can be found on the homepage https://airborne-region.nl/ half way through. LOCATIE is the location field, which is now set as Location Name to prevent double entries, this needs to change to location town, but shown once and not 5 times for example. This is the code I have tried for the location town:

    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'=>$location_ids) );
        if ( is_array($locations) && count($locations) > 0 ) {
          foreach ( $locations as $loc ) {
            $item->asp_f_dropdown_value[] = array(
            	$loc->location_id, $loc-> location_town
            );
          }
        }
      }
      return $item;
    }

    I hope you can assist as soon as possible, it would be great if we can get this working soon.

    Thank you in advance for your time.
    Marieke

    #23061
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Well, if I understand correctly, you have duplicates within the location filter.
    That code looks perfect, maybe filtering the $location_ids though an array_unique function will do the trick. So try replacing this line:

    $locations = EM_Locations::get( array('location'=>$location_ids) );

    with:

    $locations = EM_Locations::get( array('location'=>array_unique($location_ids)) );

    It may do the trick.

    Best,
    Ernest Marcinko

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


    #23075
    mar1eke_louise
    mar1eke_louise
    Participant

    Hi,

    Thank you for your response. Yes, if I use the location_town, I get dupliactes of the towns since there are duplicates. Unfortunately this code did not do the trick. The location town names are still shown as duplicates.

    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)) );
    
        if ( is_array($locations) && count($locations) > 0 ) {
          foreach ( $locations as $loc ) {
            $item->asp_f_dropdown_value[] = array(
    
    			$loc->location_id, $loc-> location_town
            );
          }
        }
      }
      return $item;
    }

    It did not do anything, I tried SORT_REGULAR, but also to no avail.

    Any other suggestions?

    Thank you again,
    Marieke

    #23082
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    I am seeing different entries within that drop-down field: https://i.imgur.com/4ybaodb.png
    Have you been able to resolve it? Or is the issue something else?

    Best,
    Ernest Marcinko

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


    #23100
    mar1eke_louise
    mar1eke_louise
    Participant

    Hi,

    No, I had to change it back to location name, so there are no double’s, but the client wants to have the location town in stead of the name, I have just turned it back to location town so you can see what is happening with above code.

    Thanks,
    Marieke

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

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


    #23121
    mar1eke_louise
    mar1eke_louise
    Participant

    Thank you again, we might almost be there but not yet.

    If I use your code the towns are doubled again in the results, so it takes in the IDs, renames it to the town name and outputs this info twice. If I remove part of the code it works in a way that the town names are shown only once but.. there is a huge amount of blank spaces above the names (I figured out these are the IDs of the other ones) and no results are found for the towns, I have attached a screenshot for you to see, since I cannot leave this on the live environment. As you can see, the towns are shown once and on alfabetical order, which is exactly what we need, but no results.

    Marieke

    Attachments:
    You must be logged in to view attached files.
    #23124
    Ernest Marcinko
    Ernest Marcinko
    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;
    }
    Best,
    Ernest Marcinko

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


    #23142
    mar1eke_louise
    mar1eke_louise
    Participant

    Thank you, this works indeed!

    But….

    When you choose a location, it gives no results found, even though there are for sure results, could you please have a look at that?

    I am very gratefull for your help and feel a bit awkward for asking so much.

    Thank you again,
    Marieke

    #23148
    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 :)


    #23182
    mar1eke_louise
    mar1eke_louise
    Participant
    You cannot access this content.
    #23203
    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 :)


    #23276
    mar1eke_louise
    mar1eke_louise
    Participant

    Hi,

    Thank you, I think it might be the ftp program you are using, I can connect with Filezila and WinScp, but not with NppFTP. Can you try connecting with another ftp program and see if you get the same error.

    By the way, you do not need to connect with a private key, just the password.

    #23560
    mar1eke_louise
    mar1eke_louise
    Participant

    Hi Ernest,

    After the latest update the entire code is not working anymore for the location filter, it is solely showing the id’s of the location now, the code for the name and or town are not working anymore, nor are the most recent codes that where.

    My client is getting very frustrated about this now and demands an asap solution for this, since the website is not working anymore because of the update.

    Could you please provide a solution?

    #23563
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    I quickly tried WinSCP and Filezilla as well, but unfortunately I am getting the same errors: https://i.imgur.com/zWwNrOm.png
    There might be an IP restriction of some sort in effect, as none of my clients can connect. Let me know if you need my IP or any other details.

    I can try guessing for other solutions, but as I said earlier, this is a custom work, and I cannot guarantee it will work permanently, in all cases. Try this:

    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(
                    'value' => $loc
                    'label' => $key
                  );
              }
            }
            $filters[$k] = $filter;
          }
        }
      }
      
      return $filters;
    }

    These are only guesses, until I can try, I won’t be able to tell if these work in any way expected.

    Best,
    Ernest Marcinko

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


Viewing 15 posts - 1 through 15 (of 23 total)

You must be logged in to reply to this topic.