#10649 closed enhancement (fixed)
Meta_key sort for numeric values / Natural Sort Order
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.0 |
| Component: | Query | Version: | 2.8.4 |
| Severity: | normal | Keywords: | has-patch commit |
| Cc: |
Description
When trying to sort posts by meta_key with numeric values the order is not "natural".
eg: 1, 10, 2, 3, 4, 5, 6, 7, 8, 9
This should be
eg: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
I have attached a simple addition to wp-includes/query.php which allows for this type of sorting.
Query use: orderby=meta_value_num
Attachments (3)
Change History (10)
- Milestone changed from Future Release to 2.9.3
- Priority changed from normal to high
Any chance of pushing this fix please? It keeps annoying me each time I upgrade WP.
or is there a blocking issue?
- Keywords dev-feedback has-patch added
- Milestone changed from 2.9.3 to 3.0
Moving to 3.0, as 2.9 is not for new enhancements/feature requests.
Perhaps another dev who's more database savy than I can comment on any particular issues which this might cause? Whilst i see none, Would be handy to know that for sure.
I think this is really a bug, simply because sorting posts via a numerical meta_key fails to work when values are > 9.
The addition of meta_value_num would be a new feature, yes, but not really required just to fix this bug (which is in the DB query).
- Keywords commit added; dev-feedback removed
- Priority changed from high to normal
Patch looks good.
Since we're here, I've made some straightforward cleanups in query.php.3.diff
- Resolution set to fixed
- Status changed from new to closed

Addition of meta_value_num