Hi @pedromfm
This is actually expected behavior.
By default ordering is done as text, so alphabetical. Numbers would be placed order of the first digit, then the second, etc.
Example:
33
3
245
23
2
11
1
You should add context to ordering (just like you need to do with WP_Query) and cast it as a number.
More info here:
– https://docs.pods.io/searching-filtering-sorting/sorting/sorting-numeric-fields-using-cast/
– https://stackoverflow.com/questions/16519648/sql-for-ordering-by-number-1-2-3-4-etc-instead-of-1-10-11-12
Cheers, Jory
Thank You, @keraweb ! I’ve just landed on a solution – just before I got the notification of your reply.
The code I used was (maybe it can be useful to others):
[pods name="places" template="List Places Cards" orderby="CAST(tours_total.meta_value AS SIGNED) DESC" limit="99" ]
in my use case I probably should be using “AS UNSIGNED” since I’m only dealing with positive numbers, but whatever.
It’s still kinda weird since numeric ordering is fairly common and it surprised me that it required such a complex expression.
(yes – I am a WP / PHP noob in case you’re wondering)
-
This reply was modified 3 years, 1 month ago by
pedromfm.
Hi @pedromfm
Good to hear it worked for you!
It’s still kinda weird since numeric ordering is fairly common and it surprised me that it required such a complex expression.
This is the world of code, where there is no such thing as a “common situation”. We, developers, create solutions for common situations 🙂
Cheers! Jory