Support » Plugin: Site Reviews » Order posts by rating

  • Resolved progameinc

    (@progameinc)


    Hi,
    I have been struggling in trying to solve my problem for two weeks now, I have read all the solutions you have given with surprising patience to anyone who has asked the same question, and I have not been able to move an inch. The solutions you have given are beyond my programming understanding.
    I set up a site where visitors can fill out a form describing the services they provide (frontend posting), and surfers can rate the page (the service). The page is created automatically using ACF.
    I use your plugin so that the surfers can tell about the service they received and give a score to the page, and everything works great.
    Now, I want to display on a separate page only the 5 businesses that received the highest score.
    I do not know how to program and I only use WordPress plugins.
    How do I extract the average score of each page (business) into the ACF to display it on the page of the 5 winning businesses.
    I would of course be willing to install a child theme or plugin that inserts code snippet, but I need to figure out which file to integrate the code with.`

    The page I need help with: [log in to see the link]

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    Now, I want to display on a separate page only the 5 businesses that received the highest score.

    I can give you some tips on how to do this, but please keep in mind that while Site Reviews does provide ranking and rating meta_keys on pages which have reviews assigned to them, it does not include a feature to display a list of these rated pages.

    Pages are very specific to your website design, and since Site Reviews allows you to assign reviews to any public Post Type (i.e. page, post, product, etc.), everyone would require this ranked “list” to look differently on their website.

    For this reason, I prefer to only provide the meta_keys on your reviewed pages. This allow anyone with a basic knowledge of WordPress theming to perform sorting by rating or rank themselves with a custom WP_Query (which is pretty standard for WordPress), or to use a third-party plugin which displays a list of pages and allows you to sort by a meta_key.

    1. There are plugins which you can use to display a list of pages and sort them by a meta_key. For example: https://wordpress.org/plugins/posts-in-sidebar/

    2. Site Reviews provides some code examples which will help you if you are familiar with coding or adjusting WordPress themes.

    Thread Starter progameinc

    (@progameinc)

    Thank you GeminiLabs for this prompt answer.
    1. Posts in the sidebar are not really an option for me because I use the Hello theme and it has no sidebars. Anyway, this is not the idea.
    2. Yes, I saw this explanation in the help section of the plugin. However, I didn’t know where I should use this code. Can you please clarify this? Should I insert the code to the plugin or to the theme?
    I am not afraid to try. I did backup my site.

    Plugin Author Gemini Labs

    (@geminilabs)

    Since the Hello theme is an Elementor theme, You can use the Elementor Pro “Posts” widget and use a code snippet to override the order and instead sort by the page ranking:

    Select the Posts widget:

    Add a Query ID:

    Use the Query ID in a code snippet to sort pages by rank:

    add_action('elementor/query/sorted_by_rank', function ($query) {
        $query->set('meta_query', [
            'relation' => 'OR',
            ['key' => '_glsr_ranking', 'compare' => 'NOT EXISTS'], // this comes first!
            ['key' => '_glsr_ranking', 'compare' => 'EXISTS'],
        ]);
        $query->set('orderby', 'meta_value_num');
        $query->set('order', 'DESC');
    });

    To use the snippet, make sure that you are using a child theme of your Hello theme, and then copy/paste the snippet above into the child theme’s functions.php file.

    If you need further assistance with this, please contact the Elementor support team and they should be able to help you.

    Thread Starter progameinc

    (@progameinc)

    Thank you so much!
    I will try this.

    Thread Starter progameinc

    (@progameinc)

    I did everything you told me:
    – Inserted the code to the function.php of the Hello child theme;
    – Added the query ID
    however it didn’t work.
    The order on the page is not according to the ranking. Moreover, when I change the query option from “date” to something else (i.e. “random”) all the results change, and I was sure nothing is supposed to change.
    Would you like to look at it?
    The page is called TRY and the URL is above

    Plugin Author Gemini Labs

    (@geminilabs)

    @progameinc I think in this case you will need to contact Elementor support for further help with this.

    Tell them that you want to display a list of pages on a page which are sorted DESC by a meta key value which is stored on each page. You may also wish to direct them to this topic.

    Thread Starter progameinc

    (@progameinc)

    Dear Gemini Labs,
    I don’t want to give up and it will take ages for the Elementor team to understand what I ask and answer, especially when I use Ele Custom Skin to create the posts from ACF fields.

    I would like to try the first option you suggested:

    “There are plugins which you can use to display a list of pages and sort them by a meta_key. For example: https://wordpress.org/plugins/posts-in-sidebar/”

    I installed a new sidebar and the Posts-in Sidebar plugin, and it is available in the Elementor widgets.
    Can you please specify which meta_key and meta value should I use?
    The Posts-in Sidebar plugin asks this:
    – Get posts with this meta key
    – Get posts with this meta value

    Thank you so much for your patience.

    Plugin Author Gemini Labs

    (@geminilabs)

    To learn how to configure the Posts in Sidebar widget, please see: https://wordpress.org/support/topic/default-rating-for-a-custom-post-type/#post-11239716

    You can use either _glsr_average OR _glsr_ranking as the meta key, depending on how you want to sort your pages.

    And for an easy way to display the rating above the page excerpts, please see: https://pastebin.com/gTqdNAyF

    Thread Starter progameinc

    (@progameinc)

    Hi Gemini Labs,
    Before I tried to configure the Posts-in-Sidebar widget, suddenly the order by rating you first suggested (with the query in the child theme) started to work.
    Maybe because I had to logout and login again to restart the theme with the child theme.
    Now the order by rating is perfect.
    Thank you very much for your patient help. You deserve 6 stars for the plugin and for the support as well.

    Plugin Author Gemini Labs

    (@geminilabs)

    Maybe it was due to a caching plugin.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Order posts by rating’ is closed to new replies.