WordPress.org

Ready to get started?Download WordPress

Forums

Duplicate posts in loop.php (4 posts)

  1. igeekout
    Member
    Posted 3 years ago #

    Im trying to grab posts in the loop by post_type. I only want to display 4 posts. But 24 posts appear.

    Any ideas?

    Here is my code:

    <?php elseif ( is_home() ) : ?>
                    <?php $my_query = new WP_Query( array( 'post_type' => 'portfolio', 'posts_per_page' => 4, 'order' => 'ASC', 'cat' => 8) ); ?>
                    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
                    <div class="other-works">
    		<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                        <div class="title-bg">
                            <h2 class="entry-title">
                                <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?> > </a>
                            </h2>
                        </div>
                            <div class="post-thumb">
                                <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail();?></a>
                            </div>
                    </div>
                    </div>
                    <?php endwhile; ?>
            <?php else: ?>
  2. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    Do you have another Loop on that page?

  3. igeekout
    Member
    Posted 3 years ago #

    Yes, this is within the loop in loop.php

  4. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    You can't nest Loops like that. As you've seen, you get some pretty unpredictable results. See this Codex page for examples of how to use multiple Loops.

Topic Closed

This topic has been closed to new replies.

About this Topic