Last active
September 9, 2021 22:55
-
-
Save vielhuber/da7711ff20acdb6ac18b15091b48c70d to your computer and use it in GitHub Desktop.
get_posts get total count with wp_query / use wp_query without a loop #wordpress
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 | |
/* fill in args from https://gist.github.com/luetkemj/2023628 */ | |
$args = []; | |
$wp_query = new \WP_Query($args); | |
if($wp_query->found_posts > 0 ) { | |
foreach($wp_query->posts as $posts__value) { | |
/* ... */ | |
} | |
} | |
// debug query | |
echo $wp_query->request; | |
// manually start loop | |
if ($wp_query->have_posts()) { | |
while ($wp_query->have_posts()) { | |
$wp_query->the_post(); | |
echo get_the_title(); | |
} | |
} | |
wp_reset_postdata(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment