How to print the excuted sql right after its execution

The $wpdb object has some properties getting set for that:

global $wpdb;

// Print last SQL query string
echo $wpdb->last_query;

// Print last SQL query result
echo $wpdb->last_result;

// Print last SQL query Error
echo $wpdb->last_error;

Note: First of all you have to set define( 'SAVEQUERIES', true ); in your wp-config.php file at root folder of WordPress.

Leave a Comment