Skip to content

Instantly share code, notes, and snippets.

@krogsgard
Last active December 19, 2015 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krogsgard/5915706 to your computer and use it in GitHub Desktop.
Save krogsgard/5915706 to your computer and use it in GitHub Desktop.
Don't copy this. It's just a sample of doing it wrong.
<?php
/*
* WP_Query doing_it_wrong
*
* i'm commenting this so you don't copy / paste this fail sauce
*/
$original_query = $wp_query; // YUDOTHAT???
$wp_query = null; // Oh, man
$args = array (
'post_type' => 'post',
'author' => 5 // these args can be whatever
);
$wp_query = new WP_Query( $args ); // you're killing kittens
if ( $wp_query->have_posts() ) {
while ( $wp_query->have_posts() ) {
$wp_query->the_post();
// do stuff
}
} else {
// aww, no posts... do other stuff
}
$wp_query = null; // ugh
$wp_query = $original_query; // sigh face
wp_reset_query(); // guess so. in a normal WP_Query, only wp_reset_postdata() is needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment