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

Convert large numbers for the Range Slider

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Convert large numbers for the Range Slider

  • This topic has 4 replies, 2 voices, and was last updated 5 years ago by J94J94.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #33060
    J94J94
    Participant

    Hi,

    How do I convert numbers for the Range Slider?

    Here’s the problem. I have a custom field containing large numbers (say 500,000,000). I want to use the Range Slider to allow users to select a range, but I want it to show the numbers in millions (aka 500 million). This custom field has a range that goes from 1,000,000 to 2,000,000,000 (1 million to 2,000 million). How do I get a 1,000,000 number to be shown as 1 (million) in the Range Slider?

    Please see the website URL for example.

    Thx.

    #33064
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    Interesting question. I think the best possible approach is to use the range slider as 1 to 2000 and add the “million” as the suffix. Then using a custom code right before the search multiply the values by 1000000.

    Try adding this code 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) {
    	$field = "meta_field_name";	// enter the field name here
    
    	foreach( $args['post_meta_filter'] as &$filter ) {
    		if ($filter['key'] == $field && is_array($filter['value'])) {
    			foreach ($filter['value'] as $k=>&$v) {
    				$v = $v * 1000000;
    			}
    		}
    	}
    	return $args;
    }

    Don’t forget to change the $field variable to the field name.

    #33070
    J94J94
    Participant

    Seems to work. Excellent feedback! Thank you.

    #33072
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

    #33131
    J94J94
    Participant

    You cannot access this content.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Convert large numbers for the Range Slider’ is closed to new replies.