• Resolved pedromfm

    (@pedromfm)


    Hi I have a shortcode to display my pods ordered by a numeric field.

    [pods name="places" template="List Places Cards" orderby="place_order.meta_value DESC" limit="99" ]

    however, the items are displayed like: 3, 23, 14, 10 ,1, etc.
    Can you help me? I just don’t understand what’s causing this behaviour.

    I’m using WordPress 6.2, PODs 2.9.13?and Elementor Pro 3.12.1.
    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    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

    Thread Starter pedromfm

    (@pedromfm)

    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 1 year, 7 months ago by pedromfm.
    Plugin Author Jory Hogeveen

    (@keraweb)

    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

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘ORDERBY is ordering items wrong’ is closed to new replies.