Query Post Multiple Loops
-
Ok so I know you can only query a loop once and then you need to create a new query for any additional loop or use get_post. I am building out a page that requires 8 loops. And I really need to use the if attribute in case one of the loops doesn’t have any content which will be the case at times. From what I can tell, you can’t use the if attribute after the main post. This is what I have:
<!-- SUNDAY LOOP --> <?php query_posts( array( 'post_type' => 'programming', 'schedule' => 'sunday', 'orderby' => menu_order )); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <?php the_excerpt('...read more'); ?> <p><?php $key="program_time"; echo get_post_meta($post->ID, $key, true); ?> EST</p> <?php endwhile; ?> <?php else : ?> <p>Healthy programming coming soon!</p> <?php endif; ?> <!-- MONDAY LOOP --> <?php query_posts( array( 'post_type' => 'programming', 'schedule' => 'monday', 'orderby' => menu_order )); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <?php the_excerpt('...read more'); ?> <p><?php $key="program_time"; echo get_post_meta($post->ID, $key, true); ?> EST</p> <?php endwhile; ?> <?php else : ?> <p>Healthy programming coming soon!</p> <?php endif; ?> <!-- TUESDAY LOOP --> <?php query_posts( array( 'post_type' => 'programming', 'schedule' => 'tuesday', 'orderby' => menu_order )); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <?php the_excerpt('...read more'); ?> <p><?php $key="program_time"; echo get_post_meta($post->ID, $key, true); ?> EST</p> <?php endwhile; ?> <?php else : ?> <p>Healthy programming coming soon!</p> <?php endif; ?> <!-- WEDNESDAY LOOP --> <?php query_posts( array( 'post_type' => 'programming', 'schedule' => 'wednesday', 'orderby' => menu_order )); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <?php the_excerpt('...read more'); ?> <p><?php $key="program_time"; echo get_post_meta($post->ID, $key, true); ?> EST</p> <?php endwhile; ?> <?php else : ?> <p>Healthy programming coming soon!</p> <?php endif; ?> <!-- THURSDAY LOOP --> <?php query_posts( array( 'post_type' => 'programming', 'schedule' => 'thursday', 'orderby' => menu_order )); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <?php the_excerpt('...read more'); ?> <p><?php $key="program_time"; echo get_post_meta($post->ID, $key, true); ?> EST</p> <?php endwhile; ?> <?php else : ?> <p>Healthy programming coming soon!</p> <?php endif; ?> <!-- FRIDAY LOOP --> <?php query_posts( array( 'post_type' => 'programming', 'schedule' => 'friday', 'orderby' => menu_order )); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <?php the_excerpt('...read more'); ?> <p><?php $key="program_time"; echo get_post_meta($post->ID, $key, true); ?> EST</p> <?php endwhile; ?> <?php else : ?> <p>Healthy programming coming soon!</p> <?php endif; ?> <!-- SATURDAY LOOP --> <?php query_posts( array( 'post_type' => 'programming', 'schedule' => 'saturday', 'orderby' => menu_order )); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2> <?php the_excerpt('...read more'); ?> <p><?php $key="program_time"; echo get_post_meta($post->ID, $key, true); ?> EST</p> <?php endwhile; ?> <?php else : ?> <p>Healthy programming coming soon!</p> <?php endif; ?>
So far this works for me but I know I’m not marking this up correctly. Can someone advise?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Query Post Multiple Loops’ is closed to new replies.