Last active
August 29, 2015 13:57
-
-
Save banago/9626002 to your computer and use it in GitHub Desktop.
WordPress Random Testimonial Shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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