• Resolved parvy

    (@parvy)


    Hi guys,

    I’ve been reading through your past support and help, it’s amazing how responsive you are, touche!

    So, I have followed your instructions to add some custom fields to my review form.

    In review.php I can access these fields like so:
    {{ design }}

    Is it possible to access these fields also in the reviews summary?

    I want to be able to allow users to rate ‘design, price, value, etc’, then based on their ratings, to make a graph which shows a summary of all of the apps stats.

    Any help would be greatly appreciated. Thanks!

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

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

    (@geminilabs)

    You can use the rating_field option on the summary shortcode to use the ratings of a custom rating field. You can also combine this with the hide option to only display the stars.

    Please see the Shortcodes Help page to learn more about this option. Note: this option only supports rating fields created with the Review Forms add-on.

    If you want to display the stars as a bar instead of stars, you will likely need to add your own custom CSS. The shortcodes allows you to add a class option, you can isolate your custom CSS to shortcodes which contain the class you set.

    Thread Starter parvy

    (@parvy)

    Hi,

    Thanks for the above.

    Two questions.

    First:
    I have added the following custom fields:

    add_filter('site-reviews/config/forms/review-form', function ($config) {
        $config['design'] = [
            'label' => __('Select a design rating for the service', 'your_theme_domain'),
            'required' => true,
            'type' => 'rating',
        ];
        $config['ease'] = [
            'label' => __('Select a ease of use rating for the service', 'your_theme_domain'),
            'required' => true,
            'type' => 'rating',
        ];
        $config['price'] = [
            'label' => __('Select a price rating for the service', 'your_theme_domain'),
            'required' => true,
            'type' => 'rating',
        ];
        $config['features'] = [
            'label' => __('Select a features rating for the service', 'your_theme_domain'),
            'required' => true,
            'type' => 'rating',
        ];
        $config['feedback'] = [
            'label' => __('Select a feedback rating for the service', 'your_theme_domain'),
            'required' => true,
            'type' => 'rating',
        ];
        $config['testings'] = [
            'label' => __('Test stuff', 'your_theme_domain'),
            'required' => true,
            'type' => 'textarea',
        ];
        return $config;
    });

    If I now wanted to access these to show in the reviews-summary, what would I add to the shortcode to show them? Would it be, for instance:

    [site_reviews_summary class="rating-bar" rating_field="design" assigned_posts="12"]

    With the above example, I can’t figure out how to actually show the additional custom fields (design, ease, price, features, feedback)

    Second:
    If I was instead to create a custom shortcode with the example give here: https://pastebin.com/MCDxctJ5

    How would I access the overall rating of the custom fields, such as (design, ease, price, features, feedback)

    If there isn’t a way to access the overall rating, is there a way to get an array of all the ratings for the above?

    Lastly, could you share a link for your documentation please. I’ve had a look but found it difficult to find, and it may be helpful in figuring out a solution ??

    Thanks for all your help in advance.

    • This reply was modified 3 years, 4 months ago by parvy.
    • This reply was modified 3 years, 4 months ago by parvy.
    • This reply was modified 3 years, 4 months ago by parvy.
    • This reply was modified 3 years, 4 months ago by parvy.
    • This reply was modified 3 years, 4 months ago by parvy.
    Plugin Author Gemini Labs

    (@geminilabs)

    1. This is correct: [site_reviews_summary class="rating-bar" rating_field="design" assigned_posts="12"]

    However, I can’t guarantee that the rating_field option will work if you are not using the Review Forms add-on, as adding custom fields without the add-on is not supported here.

    The Summary shortcode only works for one rating field. If you want to display the summary for multiple rating fields, you will need to use a separate shortcode for each, which is why you may prefer to build your own custom summary shortcode using the glsr_get_ratings function.

    2. To access the custom rating field with the glsr_get_ratings function, pass the rating_field option to it in the arguments array.

    Please see the Site Reviews > Help page for the full plugin documentation.

    Thread Starter parvy

    (@parvy)

    Thanks for the thorough response.

    I wasn’t able to find the documentation (sorry!).

    However, I was able to figure out accessing my custom fields in both the site_reviews_summary and also how to create a custom shortcode using glsr_get_ratings($atts)

    For anyone who is curious on the latter, you can use the following code to display, for instance, just the star rating for ‘design’:

    add_shortcode('glsr_summary_new', function ($atts) {
        $atts = wp_parse_args($atts, [
            'display' => 'rating',
            'class' => '',
            'style' => '',
            'text' => '',
            'rating_field' => 'design',
        ]);
        if (!function_exists('glsr_get_ratings') || !function_exists('glsr_star_rating')) {
            return 'This shortcode requires Site Reviews.';
        }
        $ratingInfo = glsr_get_ratings($atts);
        $text = wpautop($atts['text']);
        if ('count' === $atts['display']) {
            $heading = $ratingInfo->reviews;
        } elseif ('recommend' === $atts['display']) {
            $positive = $ratingInfo->ratings[4] + $ratingInfo->ratings[5];
            $percent = round(($positive / $ratingInfo->reviews) * 100);
            $heading = sprintf('%d%%', $percent);
        } else {
            $heading = number_format($ratingInfo->average, 1);
            $text .= glsr_star_rating($ratingInfo->average, $ratingInfo->reviews);
        }
        return sprintf('<div class="glsr %s" style="%s"><h3>%s</h3>%s</div>',
            $atts['class'],
            $atts['style'],
            $heading,
            $text
        );
    });

    I’m going to develop this more and will paste the final code + url for anyone who will need this in the future.

    Thanks!

    Plugin Author Gemini Labs

    (@geminilabs)

    I wasn’t able to find the documentation (sorry!).

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add custom fields to reviews-summary’ is closed to new replies.