public

Very simple script for debugging queries

  • Download Gist
debugging-main-query.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<?php
 
/**
* 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;
}
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.