In my View I have set the Ordering to Price Field - Ascending - As a number. And it sort of works. It is reading the numbers by only the first number of the price, and not as a REAL number. Meaning it thinks 1,350,000 is LESS than 699,999, I guess because 1,350,000 starts with a "1"?? How do I get them to descend lowest to highest as real numbers?
hidden link
Hi,
Thank you for contacting us and I'd be happy to assist.
I've performed some tests on my website with a "number" type price custom field and it orders the results correctly.
Can you please make sure that your price field is also a "number" type field and you're storing numerical price values like "1350000" and not the values with the thousand separators like "1,350,000"? If you're storing the price values with thousand separators then they will be treated as strings and not numbers.
In case you're already storing the numeric price values and the issue still persists, you're welcome to share temporary admin login details in reply to this message.
Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.
regards,
Waqar
Hi Waqar,
I totally understand and it works when I make the price field a "number'. However, homes prices are not written without the thousand separators, so is there a way to order the listings by price with the separators? That is what my client wants.
thanks for any help,
Mike
Hi Mike,
Thanks for the update and glad that it works.
To convert the numeric value, into a formatted price on the front-end, you can register a custom shortcode. For example:
function format_my_number($atts)
{
$atts = shortcode_atts(
array(
'num' => '',
'sym' => '',
),
$atts
);
$num = $atts['num'];
return $atts['sym'].' '.number_format($num, 0, '.', ',');
}
add_shortcode('format-currency', 'format_my_number');
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
Then, in your content template where you'd like to show this formatted price, you can use this shortcode like this:
[format-currency num="[types field='price-field-slug' output='raw'][/types]" sym="$"]
Note: you'll replace "price-field-slug" with your actual field's slug.
regards,
Waqar
Awesome. I will try today. If I change the Price Field from String to Numbers will I have to re-input all the prices, or in other words will it delete the content in those fields? Right now it is a string field with the thousands separators.
If you'll change your custom field's type to "numeric" or remove the old field and add it again as a numeric field (keeping the same field slug), the field values will stay as it is.
But, those values won't be converted to numbers without the thousand separators automatically and you'll have to update them all manually.
My issue is resolved now. Thank you!