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?
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.