• Resolved sybiloniti

    (@sybiloniti)


    HI,

    I need to get the rating on each card on the archive page of a custom post. I use twig template in Unlimited Elements :

    {{ ucfunc("render","rating") }}

    and in function.php :

    function addMyTemplates($arrMyTemplates){
    $arrMyTemplates["rating"] = '[site_reviews_summary assigned_terms="solution" hide="bars,if_empty,summary"]';

    return($arrMyTemplates);
    }
    add_filter("ue_get_twig_templates","addMyTemplates");

    But what I get is an average of my ratings on each card.

    How can I get the rating of each post on the archive page ?

    Regards.

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter sybiloniti

    (@sybiloniti)

    I made a mistake in the previous message : this is what I used in the shortcode, in a loop :

    assigned_posts="item.post_list.id" instead of assigned-terms

    I also tried with post_id but nothing worked.

    Thread Starter sybiloniti

    (@sybiloniti)

    I found out another way ! In Unlimited Elements I got the rating with _glsr_average post meta and then I used :

    function get_rating($rating) {
    echo apply_filters('glsr_star_rating', null, $rating);
    }

    Regards

    Plugin Author Gemini Labs

    (@geminilabs)

    How are you getting the _glsr_average meta value?

    If assigned_posts="post_id" doesn’t work, it’s likely because the global $post isn’t being set in The Loop.

    Since you are using PHP anyway and if you have access to the Post ID, try something like this:

    $shortcode = sprintf('[site_reviews_summary assigned_posts="%s" hide="bars,if_empty,summary"]', $postId);

    Keep in mind that the assigned_posts option will only work if you have been assigning reviews to your posts.

    • This reply was modified 2 months, 1 week ago by Gemini Labs.
    Thread Starter sybiloniti

    (@sybiloniti)

    Hi,

    I can’t get your solution to work.

    In Unlimited Element HTML item template :

    {% set rating = getPostMeta(item.post.id,"_glsr_average") %}

    Then in a div :

    {% set stars = getByPHPFunction('get_rating',rating) %}

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.