Problems with pagination and custom post types (4 posts)

  1. jamesrwhite
    Posted 5 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:

    ..but on the second page it shows as a 404 error:

    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.

    $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

    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
    Posted 5 years ago #

    Hi James,

    Try making it so all the page links appear as so


    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
    Posted 5 years ago #

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

  4. sacredpractice
    Posted 5 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