开发者

How to query WordPress Posts order by rating based on another table that contents the ratings for each post ID

I have a table that saves the ratings for each post, the table 开发者_如何学编程looks like this http://d.pr/YIxL it saves the ID of the post and the rating, I need to query the posts based on that table ASC or DSC.

I hope that the answer is clear.


This was the query that did the trick

        $wp_query->request = "
        SELECT $wpdb->posts.* FROM $wpdb->posts
        Left join $ratings_table
        ON $wpdb->posts.ID = $ratings_table.ID
        Where
        $wpdb->posts.post_type =  'games' AND $wpdb->posts.post_status =  'publish'
        ORDER BY $ratings_table.points DESC
        LIMIT $ppp OFFSET $offset";

    $pageposts = $wpdb->get_results($wp_query->request, OBJECT);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜