Nesting Custom Post Type Loops
-
Hi everybody! Was wondering if anyone would be so kind to help me out. I’m trying to nest my custom post type loop into another one (which is already in its named custom template file). I’m a noob, so not quite sure if my ifs and whiles are in the correct place. The code is below, I stripped out as much as I could for brevity purposes :). The result I’m getting is 1) starts out lovely, looping the original ‘events’ loop, then the ‘speakers’ loop , then 2) takes a turn for the worse with the original ‘events’ loop containing ‘speaker’ content! Any clues? Many thanks in advance for your time and consideration!
<?php /** *Template Name: Single test */ ?> <div> <?php if ( have_posts() ): ?> <?php while (have_posts()) : the_post();?><!-- begin of loop for 'event' --> <p>Event stuff here</p> <!-- THEN nest in custom post type loop 'speakers': --> <?php query_posts('post_type=speakers'); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <p>Speaker stuff here</p> <?php endwhile; ?> <?php endif; ?> wp_reset_postdata(); <!-- THEN resume original events loop: --> <p>Event stuff here</p> </article> <?php endwhile; ?> <?php endif; ?> </div>
Viewing 15 replies - 1 through 15 (of 15 total)
Viewing 15 replies - 1 through 15 (of 15 total)
- The topic ‘Nesting Custom Post Type Loops’ is closed to new replies.