Created
May 27, 2020 10:24
-
-
Save tomjn/3e7e943f91b629325f0ec6a27922d3ca to your computer and use it in GitHub Desktop.
A standard WP_Query loop
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 | |
$args = [ | |
// parameters go here | |
]; | |
$query = new WP_Query( $args ); | |
if ( $query->have_posts() ) { | |
while ( $query->have_posts() ) { | |
$query->the_post(); | |
// display the post | |
the_title(); | |
the_content(); | |
} | |
wp_reset_postdata(); | |
} else { | |
echo "no posts were found"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that these two loop are the same in a very literal sense:
have_posts()
andthe_post()
are just wrappers around$wp_query->have_posts()
and$wp_query->the_post()