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'm trying to do some simple split testing on a category page, but W3 Cache is causing some issues.

To do the split testing, I randomly select a layout (either grid or horizontal), then I store it in a $_SESSION variable so that the page is the same for that user while they're on the site.

Then on the category-slug.php page, I just do an if statement to determine what layout to display based on the value in the $_SESSION variable.

It is all working fine, except W3 Cache is caching the page. So the $_SESSION will have a grid layout value, but a horizontal layout will actually be displayed. Obviously this skews my data.

I'd rather not disable W3 Cache since it helps reduce our page load time. Anyone have any ideas?

share|improve this question

closed as off-topic by Pieter Goosen, gmazzap, birgire, ialocin, Johannes Pille Aug 26 '14 at 12:10

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic." – Pieter Goosen, gmazzap, birgire, ialocin, Johannes Pille
If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 1 down vote accepted

I ended up just putting variables to denote the layout in the conversion link.

For example, if the layout is a grid, the url is http://site.com/page-name/?g

It doesn't consistently let me switch layouts between users, but at least the data isn't being skewed by a $_SESSION variable reporting something differently than what is being seen by the user.

share|improve this answer

If you put something in the url to differentiate the layouts then it should cache them as different pages...other than that I can't think of anything that doesn't involve modification of W3Total Cache.

share|improve this answer

You can prevent W3 from caching the $_SESSION variable by adding it to Rejected Cookies in the page cache advanced settings.

This is the same method used to prevent W3 Total from caching shopping carts that use $_SESSION variables. See this post on the WP eStore support forums for more details.

share|improve this answer
Doesn't this just prevent the entire page from being cached as opposed to just the $_SESSION variable? The description underneath that setting says "Never cache pages that use the specified cookies." If that's the case, then since I have that $_SESSION created in the header, wouldn't that prevent all my pages from being cached? – Kyle Feb 3 '12 at 16:29

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