WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a code that redirects users to a random post whenever they visit the homepage:

if (have_posts()) {
    while (have_posts()) {

The problem is that it redirects me to the same post whenever I'm not logged in. I suspect W3 Total Cache is the culprit as it puts logged in users in an exception.

However, the problem persisted even though "Cache front page" is unchecked and "index.php" and "*/" is put into the page exception list. I even tried to disable the whole thing, Page Cache, but still nothing.

Finally I tried to disable the Browser Cache and voilá, random posts! But that's not a viable solution and I don't understand how Browser Cache could be causing 'orderby=rand' to return the same posts and not Page Cache.

Any help?

EDIT: It only returns the same post when I reload page through the site (clicking a 'href="/"' link or redirecting to a 'href="/"' link through jquery. But when I reload the page through the browser adressbar it works fine. How?

share|improve this question
Have you tried to set the status header to 307? wp_redirect($url, 307) – toscho May 9 '14 at 13:29
I did, but didn't change anything. I noticed another thing however that it only returns the same post when I reload the page inside the site (Edited my question). – Tony Fire May 9 '14 at 13:39
up vote 0 down vote accepted

Solved this by changing 'Expires header lifetime' on HTML & XML to '1 second'. Not sure if this will decrease performance on other things though.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.