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?

1 Answer 1


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.

  • PLease add the relevant code parts to the answer ;)
    – kaiser
    Sep 7, 2012 at 23:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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