• Resolved Rakesh Raja

    (@rakeshraja)


    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">&rarr;</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">&rarr;</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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Rakesh Raja

    (@rakeshraja)

    Thanks Alchymyth… it worked

    here is final code for other people

    <?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">&rarr;</span>', 'twentyeleven' ) ); ?>
    
    <?php endwhile; endif;  ?>
    
    <?php
      $query = new WP_Query( array ( 'post_type' => 'performance', 'meta_key' => 'episode', 'meta_value' => '1' ) );
    while ( $query->have_posts() ) : $query->the_post();
    ?>
    
    <li><?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?></li>
    
    <?php endwhile;   ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Loop within loop’ is closed to new replies.