• Resolved lachralle

    (@lachralle)


    I tried to use the code from https://pastebin.com/naUae8zB to get a random review shortcode.

    • I created a child theme and pasted the code into functions.php.
    • Then I tried to use the shortcode [site_review_random].

    Expected:
    To get a random review.

    Current:
    Every time I added [site_review_random] anywhere WordPress threw an error in the area where the review was supposed to appear. I can’t really say what went wrong, it might be because I’m on PHP 8.1.

    Workaround/Fix
    I got the code working by adding $atts = []; in line 14 like so:

    add_shortcode('site_review_random', function ($atts) {
        $atts = [];
        $atts['orderby'] = 'random';
        $atts['per_page'] = 1;
        if ($reviews = apply_filters('glsr_get_reviews', null, $atts)) {
            $html = $reviews->build();
            return sprintf('<div class="%s">%s</div>', $html->style, $html);
        }
    });

    I post this here so it might help others. Thank you for this nice plugin with such a flexible API and thank you, too, for the random review code.

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

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Random Review Shortcode: I had to modify the pastebin code’ is closed to new replies.