get_posts inside my loop is breaking my loop
-
This piece of code is screwing up my loop on my single-CCCC.php custom post type template
<?php $posts = $posts = get_posts( array('include' => implode( ',', $_SESSION['pid'] ), 'post_type' => array('AAAA','BBBB'),'orderby' => 'rand','numberposts' => '5',) ); foreach($posts as $post) { ?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>, <?php } ?>
My loop is this…
<?php if( have_posts() ) : ?><?php while( have_posts() ) : the_post(); ?>
then this
<?php the_title(); ?>
which works fine
then
<?php $posts = $posts = get_posts( array('include' => implode( ',', $_SESSION['pid'] ), 'post_type' => array('AAAA','BBBB'),'orderby' => 'rand','numberposts' => '5',) ); foreach($posts as $post) { ?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>, <?php } ?>
then
<?php the_title(); ?>
which doesn’t work
then this
<?php endwhile; else: endif; ?>
- The topic ‘get_posts inside my loop is breaking my loop’ is closed to new replies.