Title: stop caching Mysite.com/random
Last modified: August 21, 2016

---

# stop caching Mysite.com/random

 *  [bondigor69](https://wordpress.org/support/users/bondigor69/)
 * (@bondigor69)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/stop-caching-mysitecomrandom/)
 * I have this code in my functions.php
 *     ```
       add_action('init','random_add_rewrite');
       function random_add_rewrite() {
              global $wp;
              $wp->add_query_var('random');
              add_rewrite_rule('random/?$', 'index.php?random=1', 'top');
       }
   
       add_action('template_redirect','random_template');
       function random_template() {
              if (get_query_var('random') == 1) {
                      $posts = get_posts('post_type=post&orderby=rand&numberposts=1');
                      foreach($posts as $post) {
                              $link = get_permalink($post);
                      }
                      wp_redirect($link,307);
                      exit;
              }
       }
       ```
   
 * The plugin caches this Mysite.com/random and always shows the same post.
 * How to disable that
 * [http://wordpress.org/plugins/w3-total-cache/](http://wordpress.org/plugins/w3-total-cache/)

The topic ‘stop caching Mysite.com/random’ is closed to new replies.

 * ![](https://ps.w.org/w3-total-cache/assets/icon-256x256.png?rev=1041806)
 * [W3 Total Cache](https://wordpress.org/plugins/w3-total-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/w3-total-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/w3-total-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/w3-total-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/w3-total-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/w3-total-cache/reviews/)

## Tags

 * [cache](https://wordpress.org/support/topic-tag/cache/)

 * 0 replies
 * 1 participant
 * Last reply from: [bondigor69](https://wordpress.org/support/users/bondigor69/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/stop-caching-mysitecomrandom/)
 * Status: not resolved