• First off, I have to commend this plugin, it really is the best.

    I’m trying to design a reviews site and I’d like to arrange my posts in ascending order according to highest rated posts instead of according to dates
    Thanks

    • This topic was modified 2 years, 10 months ago by sophy0.
Viewing 15 replies - 1 through 15 (of 19 total)
  • Thread Starter sophy0

    (@sophy0)

    Does it require a pro version?

    Plugin Contributor dudo

    (@dudo)

    Hello, thank you for using YASR.

    Right now it is not possible in YASR do this kind of sorting, but maybe I can help here.

    Wich shortcode are you using?

    Thread Starter sophy0

    (@sophy0)

    I’m not using any shortcode actually
    I found this “[yasr_most_or_highest_rated_posts]” but I don’t know if it’ll work

    Plugin Contributor dudo

    (@dudo)

    Here you can find the doc https://yetanotherstarsrating.com/yasr-rankings/

    You need to insert in your posts the shortcode [yasr_visitor_votes], and with [yasr_most_or_highest_rated_posts] you can display the most/highest rated posts

    Thread Starter sophy0

    (@sophy0)

    Thanks but I’m not looking to display the highest rated posts wherever.

    Since yasr stores my ratings in a database, I’d like to use that to order my posts from the highest to the lowest rated.

    Thread Starter sophy0

    (@sophy0)

    Okay
    I think I’ve got a way
    I just need to know the meta key in which the plugin stores the vote as I’ve searched in my DB’s postmeta and I haven’t found it
    Thanks for your help so far

    • This reply was modified 2 years, 10 months ago by sophy0.
    Plugin Contributor dudo

    (@dudo)

    That’s why I was asking what shortcode are you using to save votes.

    If you’re visitors are rating your posts, there is no postmeta, but YASR save ratings in his own table (_yasr_log).

    If, instead, you’re using the overall rating feature (who write the post is the only one who can rate) that value is stored as postmeta.

    Thread Starter sophy0

    (@sophy0)

    Okay I understand now
    I’m not using any shortcodes on my posts actually, I’m using the autoinsert feature to insert the ratings.

    I actually want my visitors to be rating the posts but now it isn’t saved in the postmeta, is there any way to go around it?

    I found this code to change the “order by”
    `<?php
    $q1 = new WP_Query( array(
    ‘meta_key’ => ‘xxxxx’,
    ‘orderby’ => ‘meta_value’,
    ) );

    The code makes use of the meta_key and meta value gotten from the post meta which I don’t have here.
    Please is there any code I could use to make use of the _yasr_log
    Thanks

    • This reply was modified 2 years, 10 months ago by sophy0.

    Following. This would also make sorting posts much easier for my user-review site.

    (I understand calculating and storing extra meta during every user rating could be a performance problem, but maybe a cron job that would occasionally calculate user log and store the value in two meta fields? Once a day would be good enough for me, personally.).

    _yasr_user_rating_numb,
    _yasr_user_rating_average

    Thread Starter sophy0

    (@sophy0)

    (@pcnoggin)
    Do you have any solution?

    (@sophy0), not yet, no. My plan was to incorporate it into a custom query of my own making, but if @dudo is willing to put something together, I’d rather the expert over me.

    If this falls outside the scope, I’m sure I can hack something together. I want to wait for him first though. We can’t be the only two with review sites wanting to sort our posts by user reviews.

    Edit: no pressure, @dudo. I’m willing to try something to set this up this weekend as long as you folks don’t judge my ugly coding too harshly.

    • This reply was modified 2 years, 10 months ago by pcnoggin. Reason: no pressure
    Thread Starter sophy0

    (@sophy0)

    Okay that’d be great (@pcnoggin)
    Is there anyway we could get in touch faster.
    I’d like to connect with you
    Thanks

    nifty geek at google mail place. Name’s Patrick.

    Plugin Contributor dudo

    (@dudo)

    I’ve no time now, use this code only in a dev machine, because I didn’t tested!!!!

    Use this only for testing

    add_filter('posts_join_paged','yasr_join_paged');
    add_filter('posts_where',   'yasr_where');
    add_filter('posts_groupby', 'yasr_groupby');
    add_filter('posts_orderby', 'yasr_posts_orderby');
    
    function yasr_join_paged($join_paged_statement) {
        if(is_home() && is_main_query()) {
            global $wpdb;
            return ", {$wpdb->prefix}yasr_log AS YL";
        }
        return $join_paged_statement;
    }
    
    function yasr_where($where) {
        if(is_home() && is_main_query()) {
            global $wpdb;
            return " AND YL.post_id = {$wpdb->prefix}posts.ID";
        }
        return $where;
    }
    
    function yasr_groupby($groupby) {
        if(is_home() && is_main_query()) {
            global $wpdb;
            return " YL.post_id, {$wpdb->prefix}posts.ID";
        }
        return $groupby;
    }
    
    function yasr_posts_orderby($orderby_statement) {
        if(is_home() && is_main_query()) {
            return " (ROUND(SUM(YL.vote) / COUNT(YL.post_id), 1)) DESC";
        }
        return $orderby_statement;

    With the first filter, posts_join_paged, we add the YASR table to the main query

    With the second, posts_where, we add the where clause, the post_ids must be the same.

    With the third, posts_groupby, we add the group by clause

    With the last one, we put in the order by clause the average rating, sorting by higher.

    This is to guide you if you’ve some coding skills.

    I will work on this Monday.

    Have a nice weekend,
    Dario

    • This reply was modified 2 years, 10 months ago by dudo.

    Thank you for this, Dario. I appreciate you trying to squeeze something in before the weekend.

    The script executes (after adding a bracket at the end “}”).

    (I created a quick stage copy of my site to test) In my case, I have a custom front page with no loop so this doesn’t actually show results for me. If I revert to the latest blog posts for the site, the theme shows its own custom thing (Extra theme by ET). When I remove the home page logic in the code given, it conflicts with my theme/builder.

    That said, there are parts to this that I can cherry-pick to put in custom queries I have in other places, and that alone is really helpful. Thank you.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Arrange posts and pages according to highest rated’ is closed to new replies.