Title: Display random future events
Last modified: August 22, 2016

---

# Display random future events

 *  [val-13Love](https://wordpress.org/support/users/val-13love/)
 * (@val-13love)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/display-random-future-events/)
 * Hi
 * I am trying to create a shortcode which displays 4 future random events. I found
   the code in this link: [https://wordpress.org/support/topic/events-order-1?replies=5#post-4177246](https://wordpress.org/support/topic/events-order-1?replies=5#post-4177246)
 * I’m not a coder so used an online shortcode generator. The issue is that it displays
   the same 4 events every time. I have tried refreshing the cache and added the
   shortcode to different event pages but still get the same 4 events displayed.
 * Also it displays the 4 events directly under the event title. It doesn’t matter
   where I add the shortcode it outputs to the top of the page.
 * Is anyone able to tell me what i’m missing or doing wrong please. I would like
   4 random events displayed in the same location that the shortcode is placed (
   currently the bottom of the event page).
 * Here’s the shortcode code that I have added to my functions file:
 *     ```
       // Add similarevents shortcode
       function similar_events() {
       $events = EM_Events::get(array('limit'=>4,'scope'=>'future'));
       shuffle($event);
       foreach ( $events as $EM_Event ) {
         echo '<h6>'.$EM_Event->output('#_EVENTLINK').'</h6>';
       }
       }
       add_shortcode( 'similarevents', 'similar_events' );
       ```
   
 * Here’s a link to a couple of pages with the shortcode added:
    Page 1: [http://www.black-gold.biz/whats-on/motowns-greatest-hits-how-sweet-it-is-2015-06-27/](http://www.black-gold.biz/whats-on/motowns-greatest-hits-how-sweet-it-is-2015-06-27/)
   Page 2: [http://www.black-gold.biz/whats-on/the-magic-of-motown-2015-06-25/](http://www.black-gold.biz/whats-on/the-magic-of-motown-2015-06-25/)
 * Thanks in advance for any help
    Val 🙂
 * [https://wordpress.org/plugins/events-manager/](https://wordpress.org/plugins/events-manager/)

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

 *  Plugin Support [angelo_nwl](https://wordpress.org/support/users/angelo_nwl/)
 * (@angelo_nwl)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/display-random-future-events/#post-5440134)
 * using your snippet
 *     ```
       function similar_events() {
       	$replace = "";
       	$events = EM_Events::get(array('limit'=>4,'scope'=>'future'));
       	shuffle($event);
       	foreach ( $events as $EM_Event ) {
       		$replace .= '<h6>'.$EM_Event->output('#_EVENTLINK').'</h6>';
       	}
       	return $replace;
       }
       add_shortcode( 'similarevents', 'similar_events' );
       ```
   
 *  Thread Starter [val-13Love](https://wordpress.org/support/users/val-13love/)
 * (@val-13love)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/display-random-future-events/#post-5440136)
 * Hi Angelo
 * Thanks for the updated snippet. It now positions the results in the same location
   where the shortcode is added which is great. However it is still displaying the
   same 4 events and not random events.
 * Do you by any chance have any other suggestions that will make it show random
   events please?
 * Much Thanks
    Val 🙂

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

The topic ‘Display random future events’ is closed to new replies.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.png?rev=1039078)
 * [Events Manager - Calendar, Bookings, Tickets, and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [val-13Love](https://wordpress.org/support/users/val-13love/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/display-random-future-events/#post-5440136)
 * Status: not resolved