I’m making a plugin that does a custom query on the WordPress database, and then I’m looping through the results listing each post title as a link to the actual post.
I’m using get_permalink($id)
to obtain the URI of each post, but since I’m doing this outside of the loop, my suspicion is each of these requests is making a separate database query.
I’ve checked out the function code and tried to follow what’s going on in the actual WordPress core files, but what I’m really interested in is a general way to do this, so I can make sure I’m always writing the most optimized code in all of my plugins.
Is anyone aware of the best way to accomplish this?
In wp-config.php add this line:
In your theme functions.php file (or a plugin file for that matter) you can use this:
Make sure
ABSPATH.'/sql_log.txt'
is writeble from php.Hope this helps.
Can’t comment @Poelinca Dorin answer, so just stay it here.
If you want to know what is launching your quire just add this
fwrite($log_file, $q[0] . " - ($q[1] s)". " [Stack]: $q[2]" . "nn");
instead
fwrite($log_file, $q[0] . " - ($q[1] s)" . "nn");