Skip to main content

Setting up W3 Total Cache for Events Manager

Events Manager works with W3 Total Cache and other page caching plugins without special setup for most sites. Event lists, calendars and event pages are the same for every visitor and are good candidates for caching. A few pages are specific to one visitor, and those need to be left out.

This page describes what to configure and why. The rules apply to any page cache, including server-level caches and CDNs that cache HTML. Menu names inside W3 Total Cache change between its versions, so the steps name the setting to look for and leave the exact location to W3 Total Cache's own documentation.

Before you start

Set up and test your caching plugin on its own first. Make each change below on a staging copy if you can, and test a booking as a logged-out visitor after each one.

What can be cached​

PageSafe to cache for visitors?Notes
Events list, calendar, locations, categories, tagsYesSee saved searches below.
Single event page with a booking formYes, for logged-out visitorsEvents Manager refreshes the form's security tokens after the page loads. See booking forms.
My Bookings pageNoShows the logged-in user's own bookings.
Front-end pages for managing events, locations and bookingsNoContent depends on the logged-in user.
Cart and checkout pages (Multiple Bookings Mode) ProNoContent is the visitor's own cart.
Payment pages, claim pages and join pages for online eventsNoEvents Manager already marks these as not cacheable.
  1. Turn off page caching for logged-in users. W3 Total Cache has an option for this in its page cache settings. Logged-in users see their own details in booking forms and on the My Bookings page, and one user's version must never be served to another.

  2. Exclude the per-visitor pages from the page cache by their addresses: the pages assigned in Events then Settings then Pages then Other Pages, and with Events Manager Pro, the cart and checkout pages.

  3. Add the em_search_events cookie to the list of cookies that bypass the page cache. See saved searches for the reason.

  4. Make sure requests to /wp-admin/admin-ajax.php and /wp-json/ are not cached. Caching plugins leave these alone by default. A CDN or server rule that caches every address needs an exception for both.

  5. Purge the page cache, then make a test booking in a private browser window.

Booking forms on cached pages​

A booking form contains WordPress nonces, short-lived tokens that expire within a day. A cached page can outlive them. Events Manager handles this itself: on a cached site, the booking form's script requests fresh nonces from admin-ajax.php and uses them in place of the ones in the page. This is why step 4 matters. If that request is blocked or served from a cache, visitors see an error when they submit the form.

Events Manager treats a site as cached when the WP_CACHE constant is true, which W3 Total Cache sets in wp-config.php when you enable its page cache. If your HTML is cached somewhere WordPress doesn't know about, such as a server-level cache or a CDN, switch the behavior on yourself:

wp-config.php
define( 'EM_CACHE', true );

The number of spaces shown on a cached page can be out of date until the cache refreshes. This can't cause overbooking, because every booking is checked against live availability when it is submitted. If the stale count bothers you, shorten the cache lifetime for event pages.

Saved searches​

When a visitor searches on the events page, Events Manager stores the search in a cookie named em_search_events for a month, so the page shows the same results when they come back. A page cache that ignores this cookie can store one visitor's filtered results and show them to everyone as the events page. Telling the cache to bypass requests that carry the cookie avoids that, and visitors who haven't searched still get the cached page.

Minification and script loading​

If the calendar, search form or booking form stops responding after you turn on JavaScript minification, combining or deferral, exclude Events Manager's script from it. The file is wp-content/plugins/events-manager/includes/js/events-manager.min.js. It is already minified, so excluding it costs nothing.

Object caching​

Events Manager stores loaded events, locations and bookings in the WordPress object cache. With a persistent object cache such as Redis or Memcached, enabled through W3 Total Cache or another plugin, those lookups are shared between requests. No Events Manager setting is needed for this.

Thumbnails​

Older versions of this page described caching thumbnails made by the TimThumb script. Events Manager no longer uses it. See Thumbnail caching.

Troubleshooting​

Visitors see someone else's name or email in the booking form​

A page was cached while a user was logged in. Turn off caching for logged-in users (step 1) and purge the cache.

Bookings fail with a security or nonce error on cached pages​

The request that refreshes the form's nonces is not being made or is not reaching WordPress. Check that WP_CACHE or EM_CACHE is defined as true in wp-config.php, check step 4, and check that a security plugin or firewall is not blocking admin-ajax.php for logged-out visitors.

The events page shows filtered results to everyone​

A search was cached. Add the em_search_events cookie to the cache's bypass list (step 3) and purge the cache.