Sarathlal N

Get WordPress SQL query details

When I debug WordPress, getting SQL query details is useful in some situations.

In the WordPress plugin repo, we can find some nice debug plugins to get query details. Also, we can use default WordPress options to get query details.

First, we need to add a definition in our wp-config.php.

define('SAVEQUERIES', true);

The SAVEQUERIES definition saves the database queries to an array and we can use that array to analyze those queries.

The array is stored in the global $wpdb->queries.

$wpdb->last_query
$wpdb->last_result
$wpdb->last_error

Recent Posts

  1. Handle plugin activation hook in multisite & single site - WordPress
  2. Remove edit, view, trash and quick edit links within posts list of admin screen - WordPress
  3. PHP Errors not displaying or not logging - LAMP server - Solved
  4. Display all hooks sequentialy that run on a page - WordPress
  5. Get downloadable files of a downloadable product - WooCoomerce

Your Questions / Comments

If you found this article interesting, found errors, or just want to discuss about them, please get in touch.