WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Second Query staring from the end of the first

[Resolved] Second Query staring from the end of the first

  • I have a custom post type “members”

    Im using bootstrap 3 to make a carousel displaying them so each item of the carousel has 4 “members” like:

    <div class="item active">
     <div class="row">
      <?
      $args = array( 'post_type' => 'equipo', 'posts_per_page' => 4 );
      $loop = new WP_Query( $args );
      while ( $loop->have_posts() ) : $loop->the_post();
        $some_meta 'meta', true );
      ?>
        <div class="col-md-3">
          <div class="thumbnail">
            <h4><? the_title(); ?></h4>
            <p class="meta"><? echo $some_meta; ?></p>
          </div><!-- thumbnail -->
        </div><!-- col md 3 -->
        <? endwhile; ?>
        </div><!-- row -->
     </div><!-- item active -->

    So in the second carousel item (that has another 4 members) I want to make a new query to display the next 4 members in the database:

    <div class="item"> <!-- NOTE THERE'S NO "ACTIVE" SO ITS THE SECOND ITEM -->
     <div class="row">
      <?
      $args = array( 'post_type' => 'equipo', 'posts_per_page' => 4 );
      $loop = new WP_Query( $args );
      while ( $loop->have_posts() ) : $loop->the_post();
        $some_meta 'meta', true );
      ?>
        <div class="col-md-3">
          <div class="thumbnail">
            <h4><? the_title(); ?></h4>
            <p class="meta"><? echo $some_meta; ?></p>
          </div><!-- thumbnail -->
        </div><!-- col md 3 -->
        <? endwhile; ?>
        </div><!-- row -->
     </div><!-- item active -->

    But it displays the same first 4 members.
    How can I tell wordpress not to reset the query or something like that?

Viewing 3 replies - 1 through 3 (of 3 total)
  • untested but maybe something like…

    $count=0;
      while ( $loop->have_posts() ) : $loop->the_post();
      count ++;
           if ($count < 5){
                endwhile;}

    So I came back with the answer:

    <?php
    query_posts('showposts=8');
    $ids = array();
    while (have_posts()) : the_post();
    $ids[] = get_the_ID();
    the_title();
    the_content();
    endwhile;
    ?>

    and then:

    <?php
    query_posts(array('post__not_in' => $ids));
    while (have_posts()) : the_post();
    the_title();
    the_content();
    endwhile;
    ?>

    Source: Smashing Magazine

    Nice! Glad you got it working 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Second Query staring from the end of the first’ is closed to new replies.
Skip to toolbar