Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

joh3 on "SQL Statement for getting custom postfield"

$
0
0

Hello,
I created a post_ranking field in the wp_posts table.
Now I want to get the posts sorted by their post_ranking.
I don't get any Post back with my statement:

add_filter('posts_orderby', 'ranking_order');
function ranking_order($orderby)
{global $wpdb;
$orderby = "SELECT distinct $wpdb->posts.* from $wpdb->posts where $wpdb->posts.post_type = 'listing' order by $wpdb->posts.post_ranking DESC";
return $orderby;}

I'm glad for any help!


Viewing all articles
Browse latest Browse all 8245

Trending Articles