Display Sql query that ran in wp_query

If you ran a query based on WP_Query, the query is executed with wp_query and result will be displayed by wordpress loop. And the executed query will be printed by {$query->request}.

Example :

<?php

$args = array (
		'post_type' => 'post' 
);
$query = new WP_Query ( $args ); // execute the query

wp_die ( "Last SQL-Query: {$query->request}" ); // will print the query

?>

Output :

SELECT SQL_CALC_FOUND_ROWS wp_posts.id
FROM   wp_posts
WHERE  1 = 1
       AND wp_posts.post_type = 'post'
       AND ( wp_posts.post_status = 'publish'
              OR wp_posts.post_status = 'private' )
ORDER  BY wp_posts.post_date DESC
LIMIT  0, 10