• Pete

    (@perthmetro)


    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; ?>

Viewing 1 replies (of 1 total)
  • Thread Starter Pete

    (@perthmetro)

    Fixed it, I just closed the loop before the get_post and reopened the loop after the get_post

Viewing 1 replies (of 1 total)
  • The topic ‘get_posts inside my loop is breaking my loop’ is closed to new replies.