Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Demo Setup: Events Search – Events Manager – Code needed
- This topic has 3 replies, 2 voices, and was last updated 2 years, 9 months ago by
Ernest Marcinko.
-
AuthorPosts
-
September 4, 2023 at 11:39 am #45212
Denis
ParticipantYou mention in the Demo setup for events manager a code needed to show the location names instead of the ids, but it is not provided there.. where can i get it? i tried the code i found in another support ticket.. but it does nothin unfortunately
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_name ); } } } return $item; }thanks
September 4, 2023 at 4:01 pm #45217Ernest Marcinko
KeymasterHi,
Sure!
I am not sure what happened with that knowledge base, the code just vanished and I can’t even see it in the history. Anyways, I managed to scrape out a solution from a previous ticket, which takes multiple choices and other various things into consideration:
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; }This should very likely do the trick.
September 4, 2023 at 4:06 pm #45219Denis
Participantoh yeah, it worked.. thank you
September 4, 2023 at 4:07 pm #45220Ernest Marcinko
KeymasterYou cannot access this content.
-
AuthorPosts
- You must be logged in to reply to this topic.