Create a gist now

Instantly share code, notes, and snippets.

Very simple script for debugging queries
* Will print to the page the main query used for that page. It will do this only for admins.
* This can be put in your theme's functions.php, but should be removed when its no longer needed.
add_action( 'posts_request', 'debug_post_request', 10, 2 );
function debug_post_request( $r, $query ){
if( current_user_can( 'manage_options' ) && $query->is_main_query() ){
echo '<pre>';
print_r( $query );
echo '</pre>';
return $r;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment