Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Slider Range with two custom fields?
- This topic has 5 replies, 2 voices, and was last updated 2 years, 8 months ago by
Ernest Marcinko.
-
AuthorPosts
-
October 4, 2023 at 7:25 pm #45618
ari
ParticipantHello,
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.
October 5, 2023 at 9:40 am #45622Ernest Marcinko
KeymasterHi,
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; }October 5, 2023 at 5:50 pm #45624ari
ParticipantThank you! That worked perfectly!
October 5, 2023 at 5:55 pm #45625Ernest Marcinko
KeymasterYou cannot access this content.
October 5, 2023 at 6:21 pm #45626ari
ParticipantYou cannot access this content.
October 6, 2023 at 8:57 am #45629Ernest Marcinko
KeymasterYou cannot access this content.
-
AuthorPosts
- The topic ‘Slider Range with two custom fields?’ is closed to new replies.