I have a page template where I first am getting the contents of the page, as input in the admin tool, then a loop of posts of a custom post type.
I need to split this loop up into the 2 newest posts ("featured") and then a second loop of all the remaining posts. I am trying to use code from the WP Codex, from this page but the second loop is pulling the contents of the page, not the rest of the first loop. What did I screw up?
<!-- get the contents of the WP page first -->
<?php while (have_posts()) : the_post(); ?>
<!-- page title -->
<h1 class="category-title"><?php the_title(); ?></h1>
<!-- the subtitle is the content of the page -->
<div class="category-subtitle"><?php the_content(); ?></div>
<?php endwhile; ?>
<? wp_reset_query(); ?>
<!-- end page content -->
<div class="articles">
<?php
$args = array( 'post_type' => 'onourradar', 'posts_per_page' => 2, 'orderby' => 'menu_order', 'order' => 'ASC' );
$my_query = new WP_Query($args);
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate[] = $post->ID;
//$event_date = get_post_meta($post->ID, 'event_date', true);
//$clean_date = date('F j Y',strtotime($event_date));
?>
<div class="listing">
<?php the_post_thumbnail( 'thumb', array('class' => 'featured-image') ); ?>
<div class="listing-name"><a href="<?php the_permalink(); ?>"><?php the_title();?></a></div>
<div class="subhead"><?php the_field('teaser'); ?></div>
<div class="excerpt"><?php the_excerpt(); ?></div>
</div>
<?php endwhile; ?>
<?php if (have_posts()) : while (have_posts()) : the_post();
if (in_array($post->ID, $do_not_duplicate)) continue;
?>
<div class="listing-name"><a href="<?php the_permalink(); ?>"><?php the_title();?></a></div>
<?php endwhile; endif; ?>
EDIT: This second loop seems to work, not sure if this is the proper way. Suggestions appreciated:
<?
$args = array( 'post_type' => 'onourradar', 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post__not_in' => $do_not_duplicate );
$my_query = new WP_Query($args);
while ($my_query->have_posts()) : $my_query->the_post();
?>