WordPress.org

Ready to get started?Download WordPress

Forums

Problems with pagination and custom post types (4 posts)

  1. jamesrwhite
    Member
    Posted 3 years ago #

    I'm trying to set up pagination for the categories of my Custom Post Type 'listing', I'm using the WP-Navi plugin.

    Basically it works for the first page which is:
    http://localhost/clients/win/category/listings/photographers

    ..but on the second page it shows as a 404 error:
    http://localhost/clients/win/category/listings/photographers/page/2

    For permalinks I'm using: /%postname%/%post_id%

    Before I post some snippets of my code I just want to point out I've already read through the following topic that seems to have solved most peoples issues: http://wordpress.org/support/topic/pagination-with-custom-post-type-listing?replies=36.

    <?php
    $loop = custom_query_posts( array(
       'cat' => get_cat_ID(single_cat_title( '', false )),
       'post_type' => 'any',
       'posts_per_page' => 3,
       'meta_key' => 'user_type',
       'orderby' => 'meta_value title',
       'order' => 'ASC',
       'paged' => get_query_var('paged') ? get_query_var('paged') : 1
       )
    );
    
    while (have_posts()) : the_post();
    
       // Loop content
    
    endwhile;
    
    wp_pagenavi();
    ?>

    I'm using @rafaelxy's code from the above topic for the custom_query_posts(); but it doesn't seem to have made much difference :/

    Any ideas?

  2. ollieread
    Member
    Posted 3 years ago #

    Hi James,

    Try making it so all the page links appear as so

    http://localhost/clients/win/category/listings/photographers?paged=%page%

    get_query_var('paged') ? get_query_var('paged') : 1

    This part of the code is checking for the paged variable within the WP_Query class, which is essentially $_GET['paged'] (and maybe $_POST['paged']), so because the variable isn't set, it's defaulting to 1 which is why the first page works, but the rest of the pages are being parsed by WP as part of the post URL.

  3. jamesrwhite
    Member
    Posted 3 years ago #

    I'm afraid that didn't solve it Ollie, thanks for your reply though.

  4. sacredpractice
    Member
    Posted 3 years ago #

    I am having the same issue with Custom Post Types and PageNavi. Except my pagenavi is not counting the number of posts in my Post Type. It continually says Page 1 of 1 when i have 20 posts.

    I've placed the code after the loop in the single.php template (named getting-started-T1.php) and before the endif... also tried after the endif... neither one worked.

    Anyone have this problem?
    Need major help! Thanks in advance.

Topic Closed

This topic has been closed to new replies.

About this Topic