Title: ORDERBY is ordering items wrong
Last modified: April 13, 2023

---

# ORDERBY is ordering items wrong

 *  Resolved [pedromfm](https://wordpress.org/support/users/pedromfm/)
 * (@pedromfm)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/orderby-is-ordering-items-wrong/)
 * 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](https://wordpress.org/support/users/keraweb/)
 * (@keraweb)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/orderby-is-ordering-items-wrong/#post-16654783)
 * Hi [@pedromfm](https://wordpress.org/support/users/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
   3245232111
 * 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://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](https://stackoverflow.com/questions/16519648/sql-for-ordering-by-number-1-2-3-4-etc-instead-of-1-10-11-12)
 * Cheers, Jory
    -  This reply was modified 3 years, 2 months ago by [Jory Hogeveen](https://wordpress.org/support/users/keraweb/).
    -  This reply was modified 3 years, 2 months ago by [Jory Hogeveen](https://wordpress.org/support/users/keraweb/).
 *  Thread Starter [pedromfm](https://wordpress.org/support/users/pedromfm/)
 * (@pedromfm)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/orderby-is-ordering-items-wrong/#post-16654834)
 * Thank You, [@keraweb](https://wordpress.org/support/users/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, 2 months ago by [pedromfm](https://wordpress.org/support/users/pedromfm/).
 *  Plugin Author [Jory Hogeveen](https://wordpress.org/support/users/keraweb/)
 * (@keraweb)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/orderby-is-ordering-items-wrong/#post-16655862)
 * Hi [@pedromfm](https://wordpress.org/support/users/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.

 * ![](https://ps.w.org/pods/assets/icon.svg?rev=3286397)
 * [Pods - Custom Content Types and Fields](https://wordpress.org/plugins/pods/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/pods/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/pods/)
 * [Active Topics](https://wordpress.org/support/plugin/pods/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/pods/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/pods/reviews/)

## Tags

 * [orderby](https://wordpress.org/support/topic-tag/orderby/)

 * 3 replies
 * 2 participants
 * Last reply from: [Jory Hogeveen](https://wordpress.org/support/users/keraweb/)
 * Last activity: [3 years, 2 months ago](https://wordpress.org/support/topic/orderby-is-ordering-items-wrong/#post-16655862)
 * Status: resolved