WordPress.org

Ready to get started?Download WordPress

Forums

query_post Pagination Problem (3 posts)

  1. benherbert
    Member
    Posted 3 years ago #

    Hi,

    I have created a category on my wordpress installation which is called new arrivals. Now in this category I want to show ALL posts from all my other categories - kind of like what you would find on your homepage. So I created a new category template file called category-new-arrivals.php and then put this code in it:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;  
    
    query_posts(array(
    'paged'	=> $paged,
    'category__not_in' => array(-1),
    'posts_per_page' => 50,
    ));
    ?>

    When I load the category the first page works fine, as it shows 50 items (default is 40) and posts from every category (minus the one excluded).

    However when I move to /new-arrivals/page/2/ I get a 404 not found page even though I check for the page number at the start and use it in the query_posts

    Can anyone explain why this is happening and how to fix it?

    Thanks

  2. benherbert
    Member
    Posted 3 years ago #

    Must add that the new arrivals category is obviously blank and not filled with any posts because I thought I could overwrite the query every page load to show what I wanted.

  3. Mark / t31os
    Moderator
    Posted 3 years ago #

    You don't need a negative value for data fed into category__not_in, it's an exclusion parameter so it simply expects IDs..

    You only need negative values when using cat which accepts both inclusions and exclusions.

    Regarding the paging problem, does the same problem occur using default permalinks, ie. off? (read on first though).

    NOTE: By doing this..

    query_posts(array(
    'paged'	=> $paged,
    'category__not_in' => array(-1),
    'posts_per_page' => 50,
    ));

    You're not correctly preserving any existing query variables..

    Try this instead..

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;  
    
    query_posts( array_merge( $wp_query->query, array(
        'paged'	=> $paged,
        'category__not_in' => array(1),
        'posts_per_page' => 50
    ) ) );
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic