Title: Shortcode and Sliders
Last modified: August 31, 2016

---

# Shortcode and Sliders

 *  Resolved [VNConsort](https://wordpress.org/support/users/vnconsort/)
 * (@vnconsort)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/shortcode-and-sliders/)
 * I am trying to get one of the sliders to show random posts. I thought I could
   make a page/post that queried 4 random posts in it and use that as the slider
   but it wouldn’t show the posts at all.
 * So I saw I could overlay a shortcode on the page instead. So I made a function
   of the exact same query and gave it a shortcode. I used that shortcode on an 
   empty page and put that page into my slider. It showed the 4 random posts but
   it broke the slider because the content was not actually in the slide.
 * I was wondering how to fix this?
 * The function I am using is this:
 *     ```
       function randompost_sc(){
       	$random = new WP_Query (array(
       		'orderby' => 'rand',
       		'post_type' => array('animereviews', 'animerants', 'gamereviews', 'gamerants'),
       		'posts_per_page' => 4) );
   
       		if ($random->have_posts()) :
       			while ($random->have_posts()) : $random->the_post(); ?>
       		<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(array(64,36)); ?></a>
       		<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
       		<?php wp_reset_postdata(); ?>
       		<?php endwhile ?>
       		<?php endif;
       }
       add_shortcode( 'randomshort', 'randompost_sc');
       ```
   
 * The result looks like this now:
 * [http://45.55.62.181/wordpress/](http://45.55.62.181/wordpress/)
 * Is this even doable? Thanks
 * [https://wordpress.org/plugins/smooth-slider/](https://wordpress.org/plugins/smooth-slider/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [VNConsort](https://wordpress.org/support/users/vnconsort/)
 * (@vnconsort)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/shortcode-and-sliders/#post-7045681)
 * Actually I tried out another widget but it was for Recent posts and used it’s
   short code. It didn’t break the slider, but fit nicely inside instead. So it 
   is how I’ve written my function. Unfortunately, I can’t find a good plugin that
   will work to get random posts from multiple post types so I was forced to make
   my own query instead.
 * I’ll put it as resolved for now since it doesn’t have to do with the slider.
 * If you think of anything I can do to help get this shortcode/function/query to
   show up in the slider, I would definitely appreciate any advice! Thanks
 *  [Ravi](https://wordpress.org/support/users/ravi17040/)
 * (@ravi17040)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/shortcode-and-sliders/#post-7045794)
 * Hello [@vnconsort](https://wordpress.org/support/users/vnconsort/)
 * Glad that it worked for you and thanks for writing back.
 * Let us know in case of any further issues or suggestions.
 * Thank you,
 * Best Regards,
    Ravi.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Shortcode and Sliders’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/smooth-slider_e7cacb.svg)
 * [Smooth Slider](https://wordpress.org/plugins/smooth-slider/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/smooth-slider/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/smooth-slider/)
 * [Active Topics](https://wordpress.org/support/plugin/smooth-slider/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/smooth-slider/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/smooth-slider/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Ravi](https://wordpress.org/support/users/ravi17040/)
 * Last activity: [10 years, 4 months ago](https://wordpress.org/support/topic/shortcode-and-sliders/#post-7045794)
 * Status: resolved