I have some query that brings around 50+ posts (I know it's not ideal but had to do that to build something the client asked..) and a set of loops to order them in a certain way and it looks like that this sequence is delaying parts of the rendering of the page.

I'd like to cache in a transient this entire block of rendered HTML, is that possible?

  • 1
    Keep in mind that transients are 'transient' and unless you have a persistent cache setup added ontop of wordpress, then theyre useless for anything that is only used once in a page. Transients are best used for things you need many times but should only need to be calculated once.
    – Tom J Nowell
    Sep 12, 2010 at 13:39
  • 1
    @Tom J Nowell you are confusing transients with cache. Cache is not persistent (unless with plugin), transients are always persistent (with or without plugin). Without plugin transients are stored in database using Settings API.
    – Rarst
    Sep 17, 2010 at 4:00
  • ah, how embarassing of me lol
    – Tom J Nowell
    Sep 17, 2010 at 9:12
  • Ops, made mistake of my own - Options API, not Settings API. :)
    – Rarst
    Sep 17, 2010 at 11:08

2 Answers 2


Transients API documentation formulates suggested usage as:

long/expensive database queries or complex processed data

Your case seems like a perfect fit for this description. On technical side you will need to concatenate your output into variable and put into transient, instead of displaying it.


If I were to implement this today, my preference would be the memcache object cache, storing the data using wp_cache_set(), possibly updating the data using WP_Cron rather than during page load.

Just how many kilobytes are we talking about?

  • I'm guessing pretty low (less then 10).. the issue is that I have quite a bit looping/juggling to sort and display the way I need to. memcache (with all its surrounding) looks a bit to much.
    – Amit
    Sep 7, 2010 at 21:19
  • 1
    Transients automatically make use of object cache if such plugin is active. There is no need to use wp_cache_set() if transient mechanics are more fitting for the task.
    – Rarst
    Sep 12, 2010 at 13:15
  • Yeah, my only question would have been the amount of data you can reasonably store in a transient. It's a LONGTEXT, so... plenty. :)
    – user66
    Sep 12, 2010 at 13:26

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.