Skip to content

Instantly share code, notes, and snippets.

@banago
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banago/9626002 to your computer and use it in GitHub Desktop.
Save banago/9626002 to your computer and use it in GitHub Desktop.
WordPress Random Testimonial Shortcode
<?php
//[random_testimonial]
function random_testimonial_func( $atts ){
$query = new WP_Query( array ( 'category__in' => array( 4 ), 'posts_per_page' => -1, 'ignore_sticky_posts' => 1, ) );
$testimonials = array();
while( $query->have_posts() ) : $query->the_post();
$testimonials[] = get_the_content();
endwhile;
$picked = array_rand($testimonials, 1);
return apply_filters('the_content', $testimonials[$picked]);
}
add_shortcode( 'random_testimonial', 'random_testimonial_func' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment