Last active
January 4, 2021 21:59
-
-
Save krogsgard/5915715 to your computer and use it in GitHub Desktop.
sample custom WP_Query the right way
This file contains hidden or 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 happy dance | |
* | |
* this is a sample WP_Query the right way | |
*/ | |
$args = array ( | |
'post_type' => 'post', | |
'author' => 5 // these args can be whatever | |
); | |
$krogsquery = new WP_Query( $args ); | |
if ( $krogsquery->have_posts() ) { | |
while ( $krogsquery->have_posts() ) { | |
$krogsquery->the_post(); | |
// do stuff | |
} | |
} else { | |
// aww, no posts... do other stuff | |
} | |
wp_reset_postdata(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment