Skip to content

Instantly share code, notes, and snippets.

@scheurta
Last active August 29, 2015 14:10
Show Gist options
  • Save scheurta/8ec63b2bdc3a8eb6ac9b to your computer and use it in GitHub Desktop.
Save scheurta/8ec63b2bdc3a8eb6ac9b to your computer and use it in GitHub Desktop.
Optimized WP_Query for retrieving all posts
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'nopaging' => true, // remove if pagination is required
'no_found_rows' => true, // remove if pagination is required
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) :
//...
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment