I have a similar issue. It seems all custom field values are strings. If there were some way to cast or convert the custom fields value as a number (float in my case, int in yours) the the order by would work.
I am trying to order by coin denominations. Values are:
.01
.05
.10
.25
.50
1.00
2.00
2.50
3.00
5.00
10.00
20.00
Order by below sorts as follows (similar to your dates):
.01
.05
.10
.25
.50
1.00
10.00
2.00
2.50
20.00
3.00
5.00
Obviously, the 10.00 and 20.00 are out of order. Is there a MySQL/SQL/WP guru who can help with this?
SELECT * FROM $wpdb->posts
LEFT JOIN $wpdb->postmeta AS coindenom ON(
$wpdb->posts.ID = coindenom.post_id
AND coindenom.meta_key = 'coin-denom'
)
LEFT JOIN $wpdb->postmeta AS coindate ON(
$wpdb->posts.ID = coindate.post_id
AND coindate.meta_key = 'coin-date'
)
LEFT JOIN $wpdb->postmeta AS coinprice ON(
$wpdb->posts.ID = coinprice.post_id
AND coinprice.meta_key = 'coin-price'
)
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 = 4
AND $wpdb->term_taxonomy.taxonomy = 'category'
AND $wpdb->posts.post_status = 'publish'
ORDER BY coindenom.meta_value, coindate.meta_value, coinprice.meta_value ASC
Calling all Guru’s. ??