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 hybrid between a WordPress installation and another database with products data.

I have custom php codes which pull product data from the external database.

I want to cache everything that's WordPress but let the custom php codes function normally.

Can this be done?

share|improve this question

You can use W3TC or WP Supercache with fragment caching as seen in the following answers:

If you're using full page cache, obviously the user session variables will get tossed within the page render specifically. However, you can wrap your session bits in dynamic fragment tags as illustrated in the answers above and they should work just fine. You can also access your session information in hooks that precede the actual cache rendering if you need to do some sort of pre-processing for the dynamic bits.

Sourcing from @Rarst's answer here for W3TC:

Example 1:
<!-- mfunc any PHP code --><!-- /mfunc -->

Example 2:
<!-- mfunc -->any PHP code<!-- /mfunc -->

Example 3:
<!--MFUNC -->
    echo rand();
<!--/mfunc -->

Example 4:
<!-- mclude path/to/file.php --><!-- /mclude -->

Example 5:
<!-- mclude -->path/to/file.php<!-- /mclude -->

WordPress uses cookies rather than sessions. Why not use cookies instead? You can access cookies easily with JavaScript AND PHP. Session variables only have server-side access natively.

share|improve this answer
PLease add the relevant code parts to the answer ;) – kaiser Sep 7 '12 at 23:01

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.