Listing WordPress Database Queries

Posted on in Programming

WordPress Horizontal Logo If you need to debug what queries your WordPress site is making, try adding the following PHP to your theme:

<?php
  foreach ( $wpdb->queries as $query ) {
    echo "$query[0]<br />";
  }
?>

For this code to work, you need to add the following line to wp-config.php:

define('SAVEQUERIES', true);

After that, you should see a list of queries that was used to generate the latest page view.

Slaptijack's Koding Kraken