WordPress ships with a bunch of nifty methods to improve performance and knowing when to use one of them could cut the number of database queries on your site by over 60%.
It has to do with the way post thumbnails are displayed in a loop.
By default, whenever get_the_post_thumbnail()
is called in the main loop for the first time, WordPress looks up data for all thumbnails that are likely to appear and caches them. Otherwise, the thumbnail data for each post needs to be fetched on each iteration of the loop at a cost of two additional queries per thumbnail: One for the attachment and one for the attachment’s meta data.
So what exactly is the method? It’s a simple function, aptly named update_post_thumbnail_cache(). (more…)