Multiple loops are not reset

My lovely colleagues have once again designed something that gives me a hard time getting it in WordPress. Surprisingly it’s something that I have done multiple times before; having recent posts and page content on one page.

The homepage is a page. Just above the page’s content there are three recent posts. For the posts I need to display the first part of the content before the <!--more--> tag.

That loop seems to work fine. Later in the template I loop through the actual page content. No matter what I do, it always gives me dodgy results.

Here’s a trimmed version of my index.php/page.php template (they happen to be identical):

<div id="content">
    <?php get_template_part('news'); ?>

    $args = array(
        'hierarchical'  => false,
        'sort_column'   => 'menu_order'

    $pages = get_pages($args);

    <?php while(have_posts()): the_post(); ?>
        <?php $id = get_the_ID(); ?>

        <div id="page-content">
            <!-- lets have a dodgy menu here! -->
            <ul id="navigation">
                <?php foreach($pages as $page): ?>
                    <li<?php echo (($page->ID !== $id) ? '': ' class="active"'); ?>>
                        <a href="<?php echo get_page_link($page->ID); ?>"><?php echo $page->post_title; ?></a>
                <?php endforeach; ?>

            <div class="content-wrapper">
                <div class="subnav-wrapper">
                    <ul id="subnavigation">
                        <li><a href="#">jaarrekeningen</a></li>
                        <li><a href="#">administraties</a></li>
                        <li><a href="#">salarisverwerking</a></li>
                        <li><a href="#">fiscaal advies</a></li>
                        <li><a href="#">overig advies</a></li>

                <div class="content"><?php the_content(); ?></div>

                <div class="clear"></div>
    <?php endwhile; ?>

    <?php get_template_part('social'); ?>

As you can see, I’m including the news template. Here it is:

$args = array('numberposts' => 3);

$posts = get_posts($args);

global $more;

<div id="news">
    <?php foreach($posts as $key => $post): setup_postdata($post); ?>
        <?php if($key > 0): ?><div class="news-item-splitter"></div><?php endif; ?>
        <?php $more = 0; ?>

        <div class="news-item">
            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

            <?php the_content('Lees meer'); ?>
    <?php endforeach; wp_reset_postdata(); ?>

    <div class="clear"></div>

What am I doing wrong?

Thanks in advance.

Solutions Collecting From Web of "Multiple loops are not reset"

At the end of your news.php, use wp_reset_query(). This will revert to the default query for that page.

Hope this helps!

Codex Function Reference for wp_reset_query()

never, ever use the variable posts in WordPress for custom loops. After changing the variable name to items in news.php everything worked excellent.

When I changed the variable post to item, it stopped working again…

<?php foreach($items as $post): setup_postdata($post); ?>
    <!-- post -->
<?php endforeach; wp_reset_postdata(); ?>