Distance Filters

This topic contains 34 replies, has 2 voices, and was last updated by Alex Meda Alex Meda 2 years, 2 months ago.

Viewing 15 posts - 1 through 15 (of 35 total)
  • Author
    Posts
  • #27404
    Alex Meda
    Alex Meda
    Participant

    Hi,
    How to I add a “Distance Filter” to my website search filters bar using Ajax Search Pro?

    #27416
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    If you mean Geo location based distance filter, then that is not possible.

    If you mean a numeric custom field based filter (a distance relative to a static number), then using a custom fields filter could work.

    Best,
    Ernest Marcinko

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


    #27475
    Alex Meda
    Alex Meda
    Participant

    I think that I didn’t explain it well. As a matter of fact I have already integrated a map where user can make a post and input a location(can be street name, city name or country). I indeed added this location field data as a filter in my search bar. The issue is that, when I am making a search activating the location filter , it shows me the exact location for sure but it includes the geo-coordinates, which I don’t want.

    EXAMPLE
    Location( user input): Montreal
    Result in filters; 45.5017° N, 73.5673° W Montreal, CANADA

    Please see the screenshot below. I want the filter to extract only the city name

    Attachments:
    You must be logged in to view attached files.
    #27488
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Looking at the screenshot, unfortunately that is not part of this plugin – it is probably the theme integrated filters of some sort. I’m afraid this is not possible.

    Best,
    Ernest Marcinko

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


    #27537
    Alex Meda
    Alex Meda
    Participant

    ok I understand but how do I set-up the following context;
    I want all the search filters to be unchecked by default and when a user is playing around with the filters, I don’t want the search to trigger automatically.
    The user must finish selecting the filters that he wanted and then clicks on search to start the research.

    Attachments:
    You must be logged in to view attached files.
    #27550
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    You can turn off the facet triggers under here: https://i.imgur.com/wD6EMaG.png
    That will prevent the search from triggering, until the search button is clicked.

    Best,
    Ernest Marcinko

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


    #27571
    Alex Meda
    Alex Meda
    Participant

    Hi,
    It went totally amazing and by this way, it makes the research experience more comfortable for the user, thank you so much!

    Another search feature that I am looking forward to set up thanks to your expertise is going be according to the following context;

    1.) Please, take a look at the following screenshot which displays the “The search-Results-List” of some custom posts.
    2.) Each result shows the following information linked to the current post: “The tittle, the author and the date”

    Now my question is to know if by the same way it displays the information above, we can use the same technique to make it display some other custom fields information ?

    Attachments:
    You must be logged in to view attached files.
    #27582
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Could be doable. First, you can turn on description fields for the isotopic results. Then, you probably have to change the description font color as well. Now the regular description should be visible below the title. Then the advanced content field allows you to display custom fields/taxonomy terms within the results.

    Best,
    Ernest Marcinko

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


    #27639
    Alex Meda
    Alex Meda
    Participant
    You cannot access this content.
    #27645
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Those look like a serialized array fields, not texts unfortunately. This is only possible to print via custom code, and even then it can be problematic.

    Based on this tutorial, I would recommend using the code below for starters.
    Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

    add_filter( 'asp_results', 'asp_custom_field_to_results', 10, 1 ); 
    function asp_custom_field_to_results( $results ) {
      $custom_fields = 'address_field'; 	        // Enter the custom field names, comma separated
      $field = 'content';               					// 'title' or 'content'
      $position = 'after';           					// 'before' or 'after'
      $delimiter = ' ';               					// character between the field value and the field
    	
      $fields = explode(',', $custom_fields);
      foreach ( $fields as $custom_field ) {
    	  $custom_field = trim($custom_field);
    	  foreach ($results as $k=>&$r) {
    		if ($r->content_type != 'pagepost') continue;
    		if ( function_exists('get_field') )
    			$meta_value = get_field( $r->id, $custom_field, true ); // ACF support
    		else
    			$meta_value = get_post_meta( $r->id, $custom_field, true );
    		$meta_value = maybe_unserialize($meta_value);	
    		if ( is_array($meta_value) ) {
    			$meta_value = implode(', ', $meta_value);
    		}		
    		// Modify the post title to add the meta value
    		if ( $meta_value != '' ) {
    		  if ( $field == 'title' ) {
    			if ( $position == 'before' )
    			  $r->title  = $meta_value . $delimiter . $r->title;
    			else
    			  $r->title  .= $delimiter . $meta_value;
    		  } else {
    			if ( $position == 'before' )
    			  $r->content  = $meta_value . $delimiter . $r->content;
    			else
    			  $r->content  .= $delimiter . $meta_value;
    		  }
    		}
    	  }
      }
     
      return $results;
    }
    Best,
    Ernest Marcinko

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


    #27708
    Alex Meda
    Alex Meda
    Participant

    Hi,
    I’m still working on it because it is not working yet.

    #27717
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    Can you provide temporary FTP and back-end access? I can try to debug the code to see what is returned there. Thanks!

    Best,
    Ernest Marcinko

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


    #27783
    Alex Meda
    Alex Meda
    Participant

    I will send you a private email including the new account username and password.

    #27785
    Alex Meda
    Alex Meda
    Participant
    You cannot access this content.
    #27788
    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 15 posts - 1 through 15 (of 35 total)

You must be logged in to reply to this topic.