Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Last active November 10, 2015 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tommcfarlin/31e1bb6d071cfd5b41b2 to your computer and use it in GitHub Desktop.
Save tommcfarlin/31e1bb6d071cfd5b41b2 to your computer and use it in GitHub Desktop.
[WordPress] Display the most recently executed WordPress query.
<?php
add_filter( 'posts_request', '_acme_view_query' );
/**
* This is a private function used for debugging purposes. It dumps the
* query that was just executed out to the top of the page.
*
* @since 1.0.0
*
* @param string $query The query that was just executed.
* @return string $query The query that was just executed, if we're on the search template.
*/
function _acme_view_query( $query ) {
if ( is_admin() && is_search() && isset( $_GET['view_query'] ) && 'true' === $_GET['view_query'] ) {
var_dump( $query );
}
return $query;
}
<?php
/**
* If the 'view_query' query string is set and has the value of 'true'
* then let's trigger the hook.
*/
if ( isset( $_GET['view_query'] ) && 'true' === $_GET['vew_query'] ) {
add_filter( 'posts_request', '_acme_view_query' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment