Is it possible to save an entire piece of rendered HTML in a transient?

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?

Related posts

Leave a Reply

2 comments

  1. 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.