• Resolved AlexPR

    (@alexpr)


    Thank you for providing such a great and flexible plugin.

    I would like to display all reviews for the current post but hide all reviews which don’t have a title, content or author specified. Those reviews should be counted regarding the rating but not displayed as they otherwise do not provide much value to the user.
    I am currently using the site_reviews_summaryshort code.

    What would be the best way to implement this?

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

    (@geminilabs)

    There isn’t currently a way to filter out reviews based on the review details (other than the rating of the review), but I possible solution is to use the settings to specify which fields of the review are required when submitting a review.

    Thread Starter AlexPR

    (@alexpr)

    Would it be possible to add this feature in an upcoming release or include it in the premium version of the plugin?

    • This reply was modified 4 years ago by AlexPR.
    Plugin Author Gemini Labs

    (@geminilabs)

    I will think about how best to implement this. It could probably be a setting, however I can see some potential problems with this request. For example:

    1. You don’t want to display reviews with an empty title, but you still want the summary rating to reflect the hidden reviews. What happens if the summary shows that the rating is for 2 reviews, but since you have hidden reviews with no title, it shows that you have no reviews. This may appear misleading on your site.

    Is that what you really want? Wouldn’t it be better to require the specific review fields that you want filled in?

    Thread Starter AlexPR

    (@alexpr)

    The main reason why I would like to avoid to require the other review fields is that many users would prefer to just click on the star rating instead of writing text. Please refer to this example (star rating on top RHS). Otherwise a site would get less star ratings because many user won’t take the time to leave full reviews. I believe it makes sense to capture the ratings from those users as well. In addition more ratings could help to rank better in Google SERP.

    Showing a different number of reviews in the summary should be no problem as long as users recognize that full reviews are not mandatory and simple star ratings are counted as well.

    Could using jquery be an option to hide empty-text reviews, e.g. as described here on StackOverflow? Would pagination work in this case?

    • This reply was modified 4 years ago by AlexPR.
    Plugin Author Gemini Labs

    (@geminilabs)

    A possible solution could be to use the site-reviews/create/review-values hook to assign a category to the review if the title/content/etc. is not empty. Then, you could use this category (i.e. “full-review”) in the [site_reviews] (i.e. [site_reviews assigned_terms=full-review]) shortcode to only display reviews in that category. This would ensure that pagination works, and no hacks required!

    /**
     * Modifies the review values before they are saved
     * Paste this in your active theme's functions.php file.
     * @param array $values
     * @return array
     */
    add_filter('site-reviews/create/review-values', function ($values) {
        if (!empty($values['title']) && !empty($values['content'])) {
            $term = wp_insert_term('full-review', 'site-review-category');
            if (is_wp_error($term)) {
                glsr_log()->error($term->get_error_message());
            } else {
                $values['assigned_terms'][] = $term['term_taxonomy_id'];
            }
        }
        return $values;
    });
    Thread Starter AlexPR

    (@alexpr)

    That looks like the perfect solution!

    Thank you for the code sample. I tried it but it does not seems to work correctly on my side. The code created the category tag "full-review" but does not assign any review (even full reviews) to this category.

    Did I miss something?

    Plugin Author Gemini Labs

    (@geminilabs)

    Underneath the $term = wp_insert_term('full-review', 'site-review-category'); line please add:

    glsr_log($term);

    Then submit a test review, go to the Site Reviews > Tools > Console page, and paste the last line in the console here.

    Thread Starter AlexPR

    (@alexpr)

    [2021-03-17 21:44:19] ERROR [/themes/enfold-child/functions.php:82] Ein Begriff mit dem angegebenen Namen existiert bereits für diese übergeordnete Taxonomie.
    [2021-03-17 21:44:19] DEBUG [/themes/enfold-child/functions.php:80] WP_Error Object
    (
        [errors] => Array
            (
                [term_exists] => Array
                    (
                        [0] => Ein Begriff mit dem angegebenen Namen existiert bereits für diese übergeordnete Taxonomie.
                    )
    
            )
    
        [error_data] => Array
            (
                [term_exists] => 128
            )
    
        [additional_data:protected] => Array
            (
            )
    
    )
    
    [2021-03-17 21:44:19] ERROR [/themes/enfold-child/functions.php:82] Ein Begriff mit dem angegebenen Namen existiert bereits für diese übergeordnete Taxonomie.
    [2021-03-17 21:45:14] WARNING [deprecated.php:128] Site Reviews no longer stores the "url" review value as meta data. Please use the glsr_get_review() helper function instead.
    Plugin Author Gemini Labs

    (@geminilabs)

    Try this:

    /**
     * Modifies the review values before they are saved
     * Paste this in your active theme's functions.php file.
     * @param array $values
     * @return array
     */
    add_filter('site-reviews/create/review-values', function ($values) {
        if (!empty($values['title']) && !empty($values['content'])) {
            $term = wp_create_term('full-review', 'site-review-category');
            if (!empty($term['term_taxonomy_id'])) {
                $values['assigned_terms'][] = $term['term_taxonomy_id'];
            } elseif (is_wp_error($term)) {
                glsr_log()->error($term->get_error_message());
            }
        }
        return $values;
    });
    Thread Starter AlexPR

    (@alexpr)

    That works great. Perfect! Thank you ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Hide Reviews with empty fields for title, content or author’ is closed to new replies.