WordPress.org

Ready to get started?Download WordPress

Forums

unsolved problems with pagination using query_posts(array (4 posts)

  1. drago stone
    Member
    Posted 3 years ago #

    I have seen many problems with people reporting pagination problems, basically the 2nd, 3rd or 4th pages showing posts identical to the first page.

    This issue has been resolved but have not seen a solution for those using arrays.

    <?php
    $post = $wp_query->post;
    $limit = get_settings('posts_per_page');
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts(array('category__and' => array(22,24)));
    ?>

    This is the code i have in my category page, and it is showing 10 posts (by default) when i click on page 2 it shows the exact same posts as page 1. Iam using the WP Navi plugin.

    However i have another category page not using arrays since it only pulls posts from one category, but the pagination works fine, here is the code:

    <?php
    $post = $wp_query->post;
    $limit = get_settings('posts_per_page');
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('category_name=Apartment - Flat&showposts='.$limit.' paged=' . $paged);
    ?>
  2. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    switch to using arrays for your queries overll....its much neater.... also, you don't include your $paged in your actual query in the top... this: paged=' . $paged so no pagiation. Heck, you define all these variables:
    $post = $wp_query->post;
    $limit = get_settings('posts_per_page');
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    BUt call none of them in your query.....

    http://go.rvoodoo.com/paginate
    is my writeup on queries and pagination.....

    <?php query_posts( array(
          'posts_per_page' => 5,
          'cat' => '10',
          'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
     ));
    ?>

    is my examples...but you can plug arrays into it simply.... for instance:

    <?php query_posts( array(
          'posts_per_page' => 5,
          'category__and' => array(22,24),
          'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),
     ));
    ?>
  3. drago stone
    Member
    Posted 3 years ago #

    hey rev voodoo

    you have saved me hours of headache

    this worked very nicely, iam in debt to you, if you need design work for anything let me know ill be happy to help out

    as you may of noticed iam not a programmer, just a designer :)

    thanks again

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    Hey thanks for the offer!

    But more importantly, glad it worked!
    Once you array out the query like that, I find it is so much easier to work with!

Topic Closed

This topic has been closed to new replies.

About this Topic