WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Second Query staring from the end of the first (4 posts)

  1. Ariel Noname
    Member
    Posted 6 months ago #

    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?

  2. Keith Driscoll
    Member
    Posted 6 months ago #

    untested but maybe something like...

    $count=0;
      while ( $loop->have_posts() ) : $loop->the_post();
      count ++;
           if ($count < 5){
                endwhile;}
  3. Ariel Noname
    Member
    Posted 6 months ago #

    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

  4. Keith Driscoll
    Member
    Posted 6 months ago #

    Nice! Glad you got it working :)

Reply

You must log in to post.

About this Topic

Tags