WordPress.org

Ready to get started?Download WordPress

Forums

WP Customer Reviews
[resolved] How to have random testimonials (19 posts)

  1. Zurd
    Member
    Posted 1 year ago #

    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/

  2. hig116
    Member
    Posted 1 year ago #

    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

  3. Zurd
    Member
    Posted 1 year ago #

    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.

  4. hig116
    Member
    Posted 1 year ago #

    Terrific! Thank you so much for sharing.

    Keith

  5. hig116
    Member
    Posted 1 year ago #

    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

  6. Zurd
    Member
    Posted 1 year ago #

    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.

  7. hig116
    Member
    Posted 1 year ago #

    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.

  8. Zurd
    Member
    Posted 1 year ago #

    But you still have a problem with editing the comments?

  9. hig116
    Member
    Posted 1 year ago #

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

  10. Zurd
    Member
    Posted 1 year ago #

    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.

  11. hig116
    Member
    Posted 1 year ago #

    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

  12. Zurd
    Member
    Posted 1 year ago #

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

  13. hig116
    Member
    Posted 1 year ago #

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

    Keith

  14. hig116
    Member
    Posted 1 year ago #

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

  15. hig116
    Member
    Posted 1 year ago #

    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

    ???

  16. Zurd
    Member
    Posted 1 year ago #

    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"]

  17. hig116
    Member
    Posted 1 year ago #

    Thanks for continuing to try and help. I'm still getting this error in the admin area.

    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 385

    Keith

  18. Zurd
    Member
    Posted 1 year ago #

    Paste me your line 385 from wp-customer-reviews.php

  19. benpines
    Member
    Posted 1 year ago #

    global $wpdb;

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.