I have come across a function before that displayed the exact SQL code that was used.
In a loop for example, but can’t remember.
Can anybody tell me that function?
I have come across a function before that displayed the exact SQL code that was used.
In a loop for example, but can’t remember.
Can anybody tell me that function?
You must be logged in to post a comment.
Hi @Keith Donegan:
If I understand your question correctly I think this is what you are looking for?
$wp_query
is a global variable that contains the current query run by the loop. If you run the above code anytime while the loop is still active or even right after the loop it should give you the SQL from the loop. Just make sure you inspect it before letting something else run that usesquery_posts()
again.If you ran a query based on
WP_Query
, it’s this:See this answer: Best Collection of Code for your functions.php file
Then add ?debug=sql to any WP URL, and it’ll output the full list of queries that were run. (And yes, it’s scary…)
If you are only interested in Loops this is what I usually use: