• Resolved angelamaria

    (@angelamaria)


    I recently updated WordPress to 4.1.1 and get_posts is altering the main loop now.

    See: http://prayerforastrugglingartist.com/2014/11/30/levi-jun-miscala/

    I even moved my get_posts query out of the main template, but it’s definitely altering the main loop.

    Code for the posts index on the left:

    <li><a href="<?php echo get_category_link(1); ?>">Testimonials</a>
        <ul>
            <?php
                $posts = get_posts( 'category=1&orderby=title' );
                foreach( $posts as $p ) {
                    ?> <li><a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo $p->post_title; ?></a></li> <?php
                }
            ?>
        </ul>
    
    </li>

    Is there any alternative I can use, since it looks like it’s broken for now?

Viewing 2 replies - 1 through 2 (of 2 total)
  • try to use a different variable name instead of $posts as this is also used in the main query;

    and do add a wp_reset_postdata() after the end of the foreach loop.

    Thread Starter angelamaria

    (@angelamaria)

    Thank you! That worked amazing 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘get_posts now altering main loop’ is closed to new replies.