Organizational Research By

Surprising Reserch Topic

in wordpress how do i display a single random post of a custom post type in a s


in wordpress how do i display a single random post of a custom post type in a s  using -'wordpress,random,widget,sidebar,custom-post-type'

I have created a custom post type - Testimonials - for a WP site I am working on. I want to display a single random testimonial in my sidebar - without using a plugin if possible. Do I need to create a text widget with the proper post query? If so, what would it look like?

Many thanks,

Cynthia
    

asked Oct 23, 2015 by kinnari
0 votes
4 views



Related Hot Questions

1 Answer

0 votes

If you want you can directly paste following code snippet in your sidebar.php where you want to show the Testimonials (make sure whether it's testimonials/Testimonials)

$args=array('post_type'=>'testimonials', 'orderby'=>'rand', 'posts_per_page'=>'1');
$testimonials=new WP_Query($args);
while ($testimonials->have_posts()) : $testimonials->the_post();
    

endwhile; wp_reset_postdata();
answered Oct 23, 2015 by bhavin

...