[wp-hackers] Seeing the Actual SQL statements WP is running when compiling the posts...

Mike Schinkel mikeschinkel at newclarity.net
Sat Dec 3 04:21:27 UTC 2011


On Dec 2, 2011, at 11:02 PM, IC IC wrote:
> Is there a way to see/output the actual SQL query wp runs for
> compiling the current page record(s)?
> 
> For learning purposes, I'd like to see what SQL query runs when we say
> 
> query_posts( 'cat=1&tag=apples+apples' );
> 
> or when I am serving a taxonomy page such as
> 
> mysite.com/fruits/apple
> 
> what's the SQL query WP is running? Can I hook into that section and
> output the SQL statement on the screen?

What dd32 said, or here is a standalone file (maybe name it "test.php"?) which can run in your website's root to display the SQL query you ask for:


<?php

include 'wp-load.php';
$query = new WP_Query('cat=1&tag=apples+apples');
echo $query->request;


-Mike


More information about the wp-hackers mailing list