Created
April 28, 2012 01:28
-
-
Save yoren/2514914 to your computer and use it in GitHub Desktop.
Minimize WordPress default 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
function alter_the_query( $request ) { | |
$dummy_query = new WP_Query(); // the query isn't run if we don't pass any query vars | |
$dummy_query->parse_query( $request ); | |
// @TODO sometimes this will help reduce queries, but sometimes won't | |
$args = array( | |
'showposts' => 1, | |
'update_post_term_cache' => 0, | |
'update_post_meta_cache' => 0, | |
'no_found_rows' => 1 // if showposts = -1, useless | |
); | |
// this is the actual manipulation; do whatever you need here | |
if ( $dummy_query->is_home() ) { | |
$request = array_merge( $args, array( | |
'post_type' => 'post' | |
) ); | |
} | |
return $request; | |
} | |
// doing so may cause the functions like is_home() work incorrectly | |
add_filter( 'request', 'alter_the_query' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment