• Resolved Jon

    (@ghostwheelie)


    I’ve got a custom post type (“news”) registered and working very well.

    I have created a custom archive template for the post type (archive-news.php), and the initial load ({domain}/news/) is functioning properly. However, trying to access previous posts (i.e. {domain}/news/page/2) results in a 404 error, even though the $query_string variable looks to be correct (paged=2&post_type=news).

    Is there a way to have a paged archive for a custom post type, or has WordPress not made it there yet?

    If it’s not yet supported, is there a preferred plugin being used for this purpose?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Jon

    (@ghostwheelie)

    Hmm, so I managed to get this working by trying a hunch.

    Here is my paging code on my archive-news.php template:

    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    global $query_string;
    query_posts( $query_string . "&posts_per_page=3&paged=" . $page);

    I was basically setting the posts per page to 3 for this particular post type only.

    So on a hunch I went into Settings > Reading and changed the “Blog pages show at most” value down to 3, and suddenly paging worked for my custom post type.

    After playing around for a bit, it seems that WordPress is using the value in Settings > Reading on page load – meaning it looks for posts 11-20 for page 2 out of the box. Only after verifying that 20 or more posts exist does it run the custom paging query. I only have 7 news posts so far, so with the default settings, a page 2 did not exist.

    I ended up setting the “Blog pages show at most” down to 1 to ensure that all future attempts at paging custom post types would work, regardless of how many I wanted to show per page.

    THANK YOU. This has to be a bug.

    Hello Guys,

    I have managed to make my page which displayed list of posttypes with pagination with a sorting order to work when I read this post first time.

    However I have not been able to make my single-work.php (template to show just a single custom posttype) to work using your code.

    With default loop, it shows my custom post type propery, but the sorting order is based on date, and that is how I have been trying to use till now. But I need to sort it with menu_order field and not date.

    If I use below code, then only the latest post is displayed on all pages.

    [Code moderated as per the Forum Rules. Please use the pastebin]

    This isn’t resolved, I am in the same situation and cannot set my post limit to 1 in the admin as I have a blog which I want around 10 posts on, even though i only want 3 on my custom post type.

    Was there ever a solution to this?

    I have a really bizarre glitch where it goes through each page just fine until it reaches the last page and then it shows, not even my 404 page, but some random broken page.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘custom post type – paged archives’ is closed to new replies.