One of the good things about WordPress is that it provides a nice abstraction to DB and you can query pretty much anything from the DB, by using the appropriate functions instead of writing the query yourself.
All though it is good, there are times when you want to see what was the actual SQL query that got generated. I faced this senarious myself, when I was debugging an issue in my Bulk Delete WordPress plugin.
It turns out that it is quite easy to do it.
WP_Query object has a method called
request that returns the SQL query that was generated.
So if you want to get the query generated by the global
$wpdb object then you can use the following code
<?php echo $GLOBALS['wp_query']->request; ?>
On the other hand, if you are using a custom
WP_Query object then you can call the
request method on your object.
$my_query = new WP_Query();
- Email Log WordPress plugin v1.9.1 released
- Email Log WordPress plugin v1.9 released
- How to find if you are on the last page of a multi-page post in WordPress
- Easy Retweet WordPress plugin v3.1 Released
- Creating custom tables with correct Character Set and Collation in WordPress
- My contributions to WordPress 4.4