Forums

[resolved] Problem with showposts (3 posts)

  1. misterpatrick67
    Member
    Posted 6 months ago #

    Hello all,

    I am running two loops because I have some wacky CSS. In any case, there is something weird happening with my code. I need the first loop to show three unique posts and then the final loop to show just one unique post from the same category. It's like I need some sort of limiter on the second loop. Here's what I have:

    <?php $my_query = new WP_Query('category_name=News&showposts=4');
      while ($my_query->have_posts()) : $my_query->the_post();
      $do_not_duplicate[] = $post->ID ?>
    
        <!-- Do stuff... -->
      <?php endwhile; ?>
    
        <!-- Do other stuff... -->
    <?php if (have_posts()) : while (have_posts()) : the_post();
     if (in_array($post->ID, $do_not_duplicate)) continue;
     update_post_caches($posts); ?>
       <!-- Do stuff... -->
      <?php endwhile; endif; ?>

    Thanks!

  2. MichaelH
    moderator
    Posted 6 months ago #

    Try wp_reset_query() after the first endwhile

  3. misterpatrick67
    Member
    Posted 6 months ago #

    Thanks. I couldn't get that to work, but stripped out some other code and it worked fine. I'm not sure why but it did. Weird. Thanks!

Reply

You must log in to post.

About this Topic