开发者

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

开发者 https://www.devze.com 2023-04-02 08:19 出处:网络
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 tab

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

精彩评论

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