Order query_posts by CAST ASC, how?
-
Hello,
I’m trying to order posts by custom field which is containing numbers only. The numbers are e.g. following:
400
800
1000
1300
4300But when I try to order them by following query:
<?php query_posts($query_string. ‘&orderby=meta_value&meta_key=saldo&order=asc&showposts=9999’) ?>It does’nt work because the column in the database where custom fields are saved is in the format “longtext”. Because of that the only thing it sorts on is the first number. So the list above, which here in my posts is correct sort will instead appear like this:
1000
1300
4300
400
800Which everybody can se is’nt correct. I have heard in another forum (not WP related) that it maybe is possible to sort “longtext” by the command:
ORDER BY CAST( kolumn AS DECIMAL ) ASCBut how do I implement this to the query_posts? It is not possible to just change the column value from “longtext” to “INT” because it is both text and numbers saved there.
So how do I solve it?
- The topic ‘Order query_posts by CAST ASC, how?’ is closed to new replies.