Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › AjaxSearchPro Events Manager. Double location towns
- This topic has 22 replies, 2 voices, and was last updated 6 years, 9 months ago by
Ernest Marcinko.
-
AuthorPosts
-
July 3, 2019 at 2:04 pm #23587
mar1eke_louise
ParticipantHi 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,
MariekeJuly 3, 2019 at 2:10 pm #23588Ernest Marcinko
KeymasterYou cannot access this content.
July 3, 2019 at 2:23 pm #23589mar1eke_louise
ParticipantYou cannot access this content.
July 5, 2019 at 10:36 am #23607Ernest Marcinko
KeymasterThank 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; }July 5, 2019 at 3:56 pm #23615mar1eke_louise
ParticipantYou are a star!!
Thank you for your time and helping out with this.
Have a nice weekend.
MariekeJuly 5, 2019 at 3:57 pm #23616Ernest Marcinko
KeymasterYou cannot access this content.
August 28, 2019 at 11:03 am #23799mar1eke_louise
ParticipantHi 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,
MariekeAugust 28, 2019 at 12:03 pm #23809Ernest Marcinko
KeymasterHi 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; } -
AuthorPosts
- The topic ‘AjaxSearchPro Events Manager. Double location towns’ is closed to new replies.