Display SQL that wordpress is running

You can use any one of these filters from /wp-includes/query.php

posts_where_request
posts_groupby_request
posts_join_request
posts_orderby_request
posts_distinct_request
posts_fields_request
post_limits_request

You can print certain parts of the query to the screen to see what’s going on under the hood.

For instance, you can add this to your functions file:

add_filter('posts_where_request', 'foo_bar', 1, 10);
function foo_bar($where){
    print_r($where);
    return $where;
}