Demo Setup: Events Search – Events Manager – Code needed

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Demo Setup: Events Search – Events Manager – Code needed

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

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #45212
    Denis
    Denis
    Participant

    You 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

    #45217
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    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.

    Best,
    Ernest Marcinko

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


    #45219
    Denis
    Denis
    Participant

    oh yeah, it worked.. thank you

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


Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.