Last active
December 19, 2015 06:59
-
-
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.
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 | |
/* | |
* 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