Last active
November 10, 2015 16:04
-
-
Save tommcfarlin/31e1bb6d071cfd5b41b2 to your computer and use it in GitHub Desktop.
[WordPress] Display the most recently executed WordPress query.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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