Skip to content

Instantly share code, notes, and snippets.

@sivel
Created June 14, 2011 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivel/1025377 to your computer and use it in GitHub Desktop.
Save sivel/1025377 to your computer and use it in GitHub Desktop.
Output or log queries generated by WordPress
<?php
if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES )
add_action( 'wp_footer', 'the_queries' );
function the_queries() {
global $wpdb;
if ( defined( 'LOGQUERIES' ) && LOGQUERIES ) {
foreach ( $wpdb->queries as $query )
error_log( trim( $query[0] ) . "\n", 3, WP_CONTENT_DIR . '/debug.log' );
} else {
echo '<pre>';
print_r( $wpdb->queries );
echo '</pre>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment