Sort Posts by Number / Convert longtext to int
-
Hello,
I want to list my custom Posts by their ranking.
The Problem is, that the meta_value is saved as a longtext in the database.
So the list shows up the wrong order:
1
10
2
3
4Here is my code of getting the data fomr the database:
add_filter('posts_orderby', 'ranking_order'); function ranking_order($orderby) { global $wpdb,$wp_query; $orderby = " (SELECT distinct $wpdb->postmeta.meta_value from $wpdb->postmeta where ($wpdb->posts.ID = $wpdb->postmeta.post_id) AND $wpdb->postmeta.meta_key ='_ranking' ORDER BY CAST('_ranking' AS DECIMAL)DESC) ASC, $wpdb->posts.post_date DESC"; return $orderby; }
I’d be glad for any help.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Sort Posts by Number / Convert longtext to int’ is closed to new replies.