I’m working on a website were a client wants to display a random testimonials that rotates on refresh. The testimonials being used are just comments people leave. So right I’m pretty much pulling the comments excerpt but I’m having trouble getting it to pull a random comment, it just pulls the latest. Is there a way to do this? This is the code I’m using:
<?php
$args = array(
'status' => approve,
'number' => 1,
'orderby' => 'rand',
);
$comments = get_comments($args); ?>
<h3 class="side-heading">Customer Tesimonials</h3>
<div class="testimonials-inner">
<div class="testimonials-inner-inner">
<?php foreach ($comments as $comment) { ?>
<p><?php
$title = get_the_title($comment->comment_post_ID);
echo get_avatar( $comment, '53' );
//echo '<span class="recommauth">' . ($comment->comment_author) . '</span>';
?>"<?php
echo wp_html_excerpt( $comment->comment_content, 72 ); ?>"
</p>
<?php } ?>
<br />
<a class="re" href="/"><h4 class="butt-sub">Tell Your Story</h4></a>
</div>
</div>
</div>
</div>
Thanks!
orderby=rand does not work for WordPress comments, only posts. See the link below for more info.
http://wordpress.org/support/topic/show-random-comment