WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a problem with my loop.php, it keeps on repeating posts. I'm guessing this might be controlled outside of this loop.php as it happens no matter what I try. Could someone please advise me as to where it might be getting this information to repeat the loop 4 times.

Here is the current loop.php

    $args = array ( 'category' => 4, 'posts_per_page' => 10);
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) :  setup_postdata($post);


    <!-- Begin Style Here -->

    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <div class="postmeta">
            <?php do_action('themezee_display_postmeta_index'); ?>

        <h2 class="post-title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>

        <div class="entry">
            <?php the_post_thumbnail('thumbnail', array('class' => 'alignleft')); ?>
            <?php the_content('<span class="moretext">' . __('Read more', 'themezee_lang') . '</span>'); ?>
            <div class="clear"></div>
            <?php wp_link_pages(); ?>

        <div class="postinfo">
            <?php do_action('themezee_display_postinfo_index'); ?>

    <!-- End Style Here -->

<?php endforeach; ?>

Thanks for any help with this

share|improve this question
What do you mean by "repeating posts": are they all identical in this foreach loop? Do you have more than 4 posts assigned to this category? – birgire Apr 4 '13 at 7:58

In order not to interfere with main wp_query I would recommend to use this hook, that I used on one of my websites.

//wp_query to buffer
$temp_query = clone $wp_query;

//Use main wp_query with attributes
$wp_query = new WP_Query( array( 'posts_per_page' => 10 ) ); 
if(have_posts()) : while(have_posts()) : the_post();
//your code with html and etc    
endwhile; endif;

//Get back to main wp_query
$wp_query = clone $temp_query;
share|improve this answer
Where do I insert this? into my code on the loop.php? – Bellatoppa Apr 4 '13 at 17:04
My index.php I'm thinking is the issue and maybe why all the posts are repeated 4 times. – Bellatoppa Apr 4 '13 at 17:11
This is most of my current index.php and I believe the problem <?php if (have_posts()) : while (have_posts()) : the_post();get_template_part( 'loop', 'index' ); endwhile; ?><?php if(function_exists('wp_pagenavi')) { // if PageNavi is activated ?><div class="more_posts"><?php wp_pagenavi(); ?></div><?php } else { // Otherwise, use traditional Navigation ?> <div class="more_posts"><span class="post_links"><?php next_posts_link(__('&laquo; Older Entries', 'themezee_lang')) ?> &nbsp; <?php previous_posts_link (__('Recent Entries &raquo;', 'themezee_lang')) ?></span> </div><?php }?><?php endif; ?> – Bellatoppa Apr 4 '13 at 17:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.