This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Slider Range with two custom fields?

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Slider Range with two custom fields?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #45618
    ariari
    Participant

    Hello,

    I wanted to do a number range search field that uses two custom fields as parameters, one for the minimum and the other for maximum. Although it seems to be the only possible option right now, using two separate ranges is not ideal as it strongly affects user experience. I was wondering if there was some way to do this.

    For the sake of clarity, I have two custom fields “minTimezone” and “maxTimezone” and wanted the user to be able to search inside that range.

    #45622
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    Well, I’m afraid this is not possible, maybe via a custom code. I have constructed a possible solution, but I could not test this, so be very careful. Make sure to create a range slider for the minTimezone custom field for this to work. The code will automatically identify and then separate it to two individual min/max query arguments with the correct fields right before the search.

    Try adding this code via the Code Snippets plugin or to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.

    add_filter("asp_query_args", "asp_query_args_change", 10, 2);
    function asp_query_args_change($args, $search_id) {
    	global $wpdb;
    	foreach ( $args['post_meta_filter'] as $k => $filter) {
    		if ( $filter['key'] == 'minTimezone' ) {
    			$min = $filter['value'][0];
    			$max = $filter['value'][1];
    			unset($args['post_meta_filter'][$k]);
    			
    			// add the min
    			$args['post_meta_filter'][] = array(
    				'key'     => 'minTimezone',
    				'value'   => $min,
    				'operator'=> '>=',
    				'allow_missing' => false 
    			);
    			
    			// add the max
    			$args['post_meta_filter'][] = array(
    				'key'     => 'maxTimezone',
    				'value'   => $max,
    				'operator'=> '<=',
    				'allow_missing' => false 
    			);
    			
    			break;
    		}
    	}
    	return $args;
    }
    #45624
    ariari
    Participant

    Thank you! That worked perfectly!

    #45625
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

    #45626
    ariari
    Participant

    You cannot access this content.

    #45629
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Slider Range with two custom fields?’ is closed to new replies.