Loop within loop
-
Ok
I am using this in a custom page template called “Episodes”
Ok here are requirements
First one is custom post type “Performance” I call posts via
query_posts( 'post_type=performance&meta_key=episode&meta_value=1' );
Next one is episode
I call posts via
query_posts( array( 'post_type' => 'episode') );
Episodes will have full episode videos while performance post type will have individual videos from that particular episode
so to chain them together i have used a custom field called “episode”
so what i want now is
main loop episode and within that another loop for performance
what i did is
<?php query_posts( array( 'post_type' => 'episode') ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php $my_meta = get_post_meta($post->ID,'_my_meta',TRUE); ?> <h1>Episode :<?php echo get_post_meta($post->ID, 'episode', true) ?></h1> <h2><?php echo get_post_meta($post->ID, 'season', true) ?></h2><Br /><br /> <?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?> query_posts( 'post_type=performance&meta_key=episode&meta_value=1' ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <li><?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?></li> <?php endwhile; endif; <?php endwhile; endif; ?>
But it gave me nested loops.. it just keep loading..
here is my desired layout
[1] Episode 1 – [custom field assigned “episode” as value of “1”]
[2] 4 Performances – [custom field assigned “episode” as value of “1”]so in output on page should be like this
[ EPISODE 1 ]
[PERFORMANCE 1] [PERFORMANCE 2] [PERFORMANCE 3] [PERFORMANCE 4]
Help
- The topic ‘Loop within loop’ is closed to new replies.