Skip Navigation

[Resolved] I want to arrange my homes by price, lowest to highest

This support ticket is created 3 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 6.13 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 6 replies, has 2 voices.

Last updated by mikeV-2 3 years, 9 months ago.

Assisted by: Waqar.

Author
Posts
#1950299

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

#1951249

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

#1951885

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

#1951997

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

#1956893

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.

#1957743

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.

#1963053

My issue is resolved now. Thank you!