[wp-hackers] Reusing queries
William Davis
will.davis at gmail.com
Fri Nov 12 19:07:17 UTC 2010
The site I'm working on doesn't use embedded images with posts but
instead uses a few functions to see if there are images attached to
the post, if those images meet a number of parameters, and finally to
display those images.
So the call for an image usually looks something like this:
if(has_image() && image_meets_params()) {
image();
}
The problem is, each of those functions queries the database, so the
number of queries on a page can potentially explode.
has_image() checks to see if there are any images attached to the post
at all
image_meets_params() grabs the first image and checks the meta to see
if it is a horizontal or vertical image and checks the width
and then finally image() displays the image or images.
Is there a way to reuse some of these queries from one function to
another, so for example if has_image returns true it then passes all
the information onto image_meets_params? Or are these queries light
enough that I need not even be worrying about it?
Will
William P. Davis
will.davis at gmail.com
207.660.5342
http://twitter.com/williampd
http://www.wpdavis.com
More information about the wp-hackers
mailing list