Display SQL that wordpress is running

I am wanting to see the actual SQL that worpress is running to build certain pages, is there a debug method or some other way to outpout this or view it?

Related posts

Leave a Reply

1 comment

  1. 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;
    }