I need to get the main query posts as an array. Example, in common tag page(tag.php), I need to get all the posts as an array ( like get_posts() do) and display it using some multiple loops instead of using default wordpress loop as shown under
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
$posts
is the variable you’re looking for it. It is the equivalent ofget_posts
results for the main query. It’s in the global namespace, so in order to access it somewhere else you’ll need to use the keywordglobal
.