Skip to main content
added 228 characters in body
Source Link
Tony Fire
  • 407
  • 1
  • 4
  • 10

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

if (have_posts()) {
    query_posts('orderby=rand');
    while (have_posts()) {
        the_post();
        wp_redirect(get_permalink());
    }
}

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?

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

if (have_posts()) {
    query_posts('orderby=rand');
    while (have_posts()) {
        the_post();
        wp_redirect(get_permalink());
    }
}

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?

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

if (have_posts()) {
    query_posts('orderby=rand');
    while (have_posts()) {
        the_post();
        wp_redirect(get_permalink());
    }
}

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?

Source Link
Tony Fire
  • 407
  • 1
  • 4
  • 10

Browser Cache causes 'Orderby=rand' to return the same posts

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

if (have_posts()) {
    query_posts('orderby=rand');
    while (have_posts()) {
        the_post();
        wp_redirect(get_permalink());
    }
}

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?