If you’re working on a project that’s built on WordPress, then you may find yourself in a situation where displaying the most recently executed query is useful. This is especially true if you’re working on a large project with a team, or if you’ve inherited a large codebase from someone else, or if you’re needing to debug the performance of a given template.
In the following video, you will see how to write a custom function that hooks into the WordPress lifecycle to display the WordPress query that was run most recently.
This particular function can be wrapped in a conditional that evaluates the presence and value of a query string variable to determine if the query should be displayed or not. This is helpful in debugging code in a staging environment.