I’m attempting to have two loops on my archive-custom.php (it’s for a custom post type) – one loop for featured post(s) and another for the rest of the posts.
This is the code I have come up with, however, it’s not working correctly. At the moment, it doesn’t display either loop and ends up actually breaking other PHP based elements.
Note: These loops are split up into different template parts – not sure if that matters or not. However, I have combined them into one chunk to make it easier to troubleshoot.
<?php $args = array (
'post_type' => 'community',
'category_name' => 'featured',);
// The Query
$community_posts_featured = new WP_Query( $args );
if ($community_posts_featured->have_posts()) : while ($community_posts_featured->have_posts()) : $community_posts_featured->the_post(); ?>
<div id="featured">
<--Featured Stuff Here-->
<?php the_content(); ?>
</div><!--End #featured-->
<?php endwhile; ?>
<?php $args = array (
'post_type' => 'community', );
// The Query
$community_posts = new WP_Query( $args );
if ($community_posts->have_posts()) : while ($community_posts->have_posts()) : $community_posts->the_post(); ?>
<div id="main-content">
<--Main Stuff Here-->
<?php the_content(); ?>
</div><!--#End Main-->
<?php endwhile; ?>
<?php else : ?>
<--Missing Content Stuff-->
<?php endif; ?>
There i can spot two problems:
1) You have opened 2 if statements and have just closed one of them
2) you’d better use
wp_reset_query();
after the first loop