WP Customer Reviews
[resolved] Random Review Widget? (6 posts)

  1. MikePayne
    Posted 5 years ago #

    I need to add a sidebar widget to show a random review whenever the page is loaded. I tried checking the source to see if it was saving the reviews as custom post types or as a comment type, but it looks like it is saving it directly to the wpdb. Is there a way to pull out a single review sorted by random? Any help is extremely appreciated. Thanks!

  2. MikePayne
    Posted 5 years ago #

    ok, so i figured out a solution (maybe not the best, but it works). i created a widget with the following code to retrieve the data directly from $wpdb.

    global $wpdb;
    $testimonial = $wpdb->get_results('SELECT * FROM wp_wpcreviews WHERE status=1 ORDER BY RAND() LIMIT 1 ');
    echo "<h2>Testimonials</h2>";
    echo "<div class=\"testimonial\"><strong>" . $testimonial[0]->review_title . " - " . $testimonial[0]->review_rating . "/5</strong><br />\n";
    echo "\"" . $testimonial[0]->review_text . "\"<br />\n";
    echo "-" . $testimonial[0]->reviewer_name . "\n";
    echo "</div>\n";

    ** Note: this was set as a widget and placed in a widgetized area. It could not be used as a shortcode. **

    It gets a row with a status of 1 ( 0 = unapproved, 1 = approved, 2 = trash ) containing a stdClass object as the first element in an array sorted by random and limited to just one row.

    the object contains:

    Hope this helped anyone else with similar needs.

  3. solvid
    Posted 5 years ago #

    Is there a widget available that shows recent reviews?

  4. bompus
    Plugin Author

    Posted 4 years ago #

    There is a shortcode available now for recent reviews. Try it with the latest version.

    Thanks for the widget code idea.. We'll see about getting some documentation added for that in a future version.

  5. MikePayne
    Posted 4 years ago #

    @solvid: I haven't seen one, but the code above will do that if you remove the randomize parameter from the $wpdb call.

    @bompus sounds good, I saw that there was an update recently, but didn't check into it at all. BTW, the function you have in there to send yourself data about the sites is very black hat. I would suggest taking it out. As is, I remove it from sites I install it on before I activate it.

  6. bompus
    Plugin Author

    Posted 4 years ago #

    The activation code, as stated in the code, is for analytics purposes only... several other (very popular) plugins utilize the same feature. I don't consider it black hat, in that it does not send any sensitive data -- simply the URL, plugin version, and version of WP being used (and I believe email address IF they chose to share it). Google Analytics and their Crawler collects the same exact information (and more). Still.. making it an opt-in is a good idea.

    We use it to see who is using the plugin and on what version of WP. It helps us to see how the plugin is being used, so we can incorporate new features and make changes, especially with themes that have issues with the code and/or CSS. In the next update, I'll try to the analytics to be part of the email opt-in process when initially installing the plugin.

    Right now, there is an opt-in to receive email updates if there are any important security/major updates to the plugin, so that would be a good place to put a checkbox to enable this feature or not.

    Glad you like the plugin.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP Customer Reviews
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic