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 3 years, 9 months ago.
- AuthorPosts
- June 7, 2019 at 8:47 am #23059
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.
MariekeJune 7, 2019 at 12:44 pm #23061Hi,
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 :)
June 10, 2019 at 9:43 am #23075Hi,
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,
MariekeJune 10, 2019 at 12:40 pm #23082Hi,
I am seeing different entries within that drop-down field: https://i.imgur.com/4ybaodb.png
Best,
Have you been able to resolve it? Or is the issue something else?
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
June 11, 2019 at 10:46 am #23100Hi,
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,
MariekeJune 11, 2019 at 11:32 am #23101Hi,
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:
Best,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; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
June 12, 2019 at 12:52 pm #23121Thank 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.June 12, 2019 at 1:31 pm #23124Hi,
Well, I am just guessing at this point, but maybe this one:
Best,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; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
June 13, 2019 at 12:26 pm #23142Thank 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,
MariekeJune 13, 2019 at 1:14 pm #23148You cannot access this content. Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
June 18, 2019 at 9:22 am #23182You cannot access this content.June 20, 2019 at 3:00 pm #23203You cannot access this content. Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
June 25, 2019 at 7:49 am #23276Hi,
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.
July 2, 2019 at 12:37 pm #23560Hi 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?
July 2, 2019 at 2:16 pm #23563Hi,
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 :)
- AuthorPosts
You must be logged in to reply to this topic.