WordPress.org

Support

Support » Plugins and Hacks » WP Customer Reviews » [Resolved] How to have random testimonials

[Resolved] How to have random testimonials

  • Random testimonials is not a feature in WP Customer reviews 2.4.5, I thought it would be fun to add this feature and it was. Hopefully, the creator of this plugin could add my code in the next release.

    Here’s how to add the feature and it’s not difficult.

    First, in the shortcode, call it with the variable RANDOM=”1″ like so :
    [WPCR_SHOW POSTID="ALL" NUM="1" SNIPPET="170" MORE="" HIDECUSTOM="0" HIDERESPONSE="0" RANDOM="1"]

    Open up wp-customer-reviews.php and add these codes at the line I’m saying, please note that it might not be the exact same lines because I modified the file before, it’s really close though.

    Line 392 :
    function get_reviews($postID, $startpage, $perpage, $status, $random) {

    Line 620 :
    function output_reviews_show($inside_div, $postid, $perpage, $max, $hide_custom = 0, $hide_response = 0, $snippet_length = 0, $show_morelink = '', $random = 0) {

    Line 627 :
    $arr_Reviews = $this->get_reviews($postid, $thispage, $perpage, 1, $random);

    Line 1297 :
    extract( shortcode_atts( array('postid' => 'all','num' => '3','hidecustom' => '0','hideresponse' => '0', 'snippet' => '0','more' => '', 'random' => '0'), $atts ) );

    Line 1306 :
    $random = intval($random);

    Line 1315 :
    $ret_Arr = $this->output_reviews_show( $inside_div, $postid, $num, $num, $hidecustom, $hideresponse, $snippet, $more, $random );

    And finally, where the magic happens, at around line 413, you should see an SQL query like so : FROM $this->dbtable WHERE $qry_status $and_post ORDER BY date_time DESC $limit, copy it one more time and modify the whole thing like so :

    if ( $random ) {
            $reviews = $wpdb->get_results("SELECT
                id,
                date_time,
                reviewer_name,
                reviewer_email,
                review_title,
                review_text,
                review_response,
                review_rating,
                reviewer_url,
                reviewer_ip,
                status,
                page_id,
                custom_fields
                FROM $this->dbtable WHERE $qry_status $and_post ORDER BY RAND() DESC $limit
                ");
    }
    else {
          	$reviews = $wpdb->get_results("SELECT
                id,
                date_time,
                reviewer_name,
                reviewer_email,
                review_title,
                review_text,
                review_response,
                review_rating,
                reviewer_url,
                reviewer_ip,
                status,
                page_id,
                custom_fields
                FROM $this->dbtable WHERE $qry_status $and_post ORDER BY date_time DESC $limit
                ");
    }

    Note that I removed the backticks in this code because they are used in this forum as a code tag. Just look at the original code and put them where they are supposed to go.

    http://wordpress.org/extend/plugins/wp-customer-reviews/

Viewing 15 replies - 1 through 15 (of 18 total)
  • Is there any chance you can share the entire code? I’m having trouble finding the right spots to tie all this in.

    Thank you,
    Keith

    Here’s my entire file :
    http://pastebin.com/Y35zkNwU

    However I added a new variable ‘show_only_one_time’, I needed to show only 1 comment in the footer of every page instead of all. If you’re using my code and probably NUM=”1″ in the shortcode, it will only list 1 comment.

    Terrific! Thank you so much for sharing.

    Keith

    The plugin looks like it’s working, but I’m getting an error in the admin. So far the only problem I see this error causing is not being about to edit the testimonials in the admin. Any thought?

    Warning: Missing argument 5 for WPCustomerReviews::get_reviews(), called in /home/content/45/10376245/html/wp-content/plugins/wp-customer-reviews/wp-customer-reviews-admin.php on line 957 and defined in /home/content/45/10376245/html/wp-content/plugins/wp-customer-reviews/wp-customer-reviews.php on line 39

    Keith

    Might be because of the permission of the file if you created a new onem make sure it’s 644.

    If you have linux, make a diff of the original file wp-customer-reviews.php and the new one, there might be more difference.

    I will make a diff of the admin.php file and the original later tonite, will keep you posted.

    I appreciate it. I didn’t create a new file and am not experienced with making a diff. Sorry. I did just finish testing and everything thing else seems to be working just fine.

    But you still have a problem with editing the comments?

    Yes. I can edit the first, top testimonial but none of the others.

    Looks like there was a problem when you copied the file.

    Line 393 should read like that :
    function get_reviews($postID, $startpage, $perpage, $status, $random)

    see, it has 5 arguments and your error is complaining about a missing fifth argument.

    Zurd,

    Sorry, I just saw your response. My code is exactly what you have on pastebin, including Line 393. I’m not sure why it’s missing the fifth argument.

    Keith

    Check the box at the bootom “Notify me”. Is it working now?

    Yes, and I had that checked before. May have ended up in spam.

    Keith

    Oh, and I meant yes to the ‘notify me’ not the plugin. I’m still getting the same error message with plugin.

    Now I’m getting this error when trying going to url:

    Warning: Cannot modify header information – headers already sent by (output started at /home/content/45/10376245/html/wp-content/plugins/wp-customer-reviews/wp-customer-reviews.php:1) in /home/content/45/10376245/html/wp-includes/pluggable.php on line 876

    ???

    headers already sent usually means you have spaces or blank lines at the top of your file before <?php or at the end completely after ?>

    Let’s try one more time, copy and paste in wp-customer-reviews.php :
    http://pastebin.com/NKe7fkxa

    And call in a WP page the plugin like so :
    [WPCR_SHOW POSTID=”ALL” NUM=”1″ SNIPPET=”170″ MORE=”” HIDECUSTOM=”0″ HIDERESPONSE=”0″ RANDOM=”1″]

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘[Resolved] How to have random testimonials’ is closed to new replies.
Skip to toolbar