Title: Orderby Problems
Last modified: August 19, 2016

---

# Orderby Problems

 *  Resolved [freshifreshy](https://wordpress.org/support/users/freshifreshy/)
 * (@freshifreshy)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/orderby-problems/)
 * I’m trying to order by a numerical value (a price). I followed the adivce I found
   on a previous post and used ORDER BY ABS(0 + $wpdb->postmeta.meta_key) ASC
 * It seemed to work great, but every now and then a single entry or two will get
   ordered out of place. I can’t seem to figure out why, but with each of my lists,
   a few entries don’t seem to want to be placed in order.
 * Not sure what to do about it…
 * Here is my query
 *     ```
       $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts
       LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
       LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
       LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
       WHERE $wpdb->term_taxonomy.term_id = 3
       AND $wpdb->term_taxonomy.taxonomy = 'category'
       AND $wpdb->posts.post_status = 'publish'
       AND $wpdb->postmeta.meta_key = 'Price'
       ORDER BY ABS(0 + $wpdb->postmeta.meta_key) ASC
       LIMIT $offset, $postsperpage", OBJECT);
       ```
   
 * Thanks!

The topic ‘Orderby Problems’ is closed to new replies.

## Tags

 * [Numbers](https://wordpress.org/support/topic-tag/numbers/)
 * [order by](https://wordpress.org/support/topic-tag/order-by/)
 * [orderby](https://wordpress.org/support/topic-tag/orderby/)
 * [price](https://wordpress.org/support/topic-tag/price/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [freshifreshy](https://wordpress.org/support/users/freshifreshy/)
 * Last activity: [17 years, 10 months ago](https://wordpress.org/support/topic/orderby-problems/)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
