Pagination not working for custom post type (3 posts)

  1. m_i_rite
    Posted 4 years ago #

    I keep getting page not found errors when trying to access the second page of posts.

    My code:

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

    And to get the links:

    <div class="navigation">
    	<div class="alignleft"><?php next_posts_link('Next 3') ?></div>
    	<div class="alignright"><?php previous_posts_link('Previous
    3') ?></div>

    The Next 3 button shows up, but when clicked it returns a 404.

    My permalink setting is:

    I've tried changing the page settings in the admin console, and the "Category pagination fix" plugin with no success.

  2. daleanthony
    Posted 4 years ago #

    I'm using WordPress 3.2 with custom post types and having the exact same problem, using news-archive.php when going to the 'next page' (/news/page/2) I get error 404.

    I've looked over just about every post in these forums with the same issue but can't seem to find a fix.

    My custom post type function: http://pastebin.com/uG1L6YNu
    My news-archive.php file: http://pastebin.com/vjcx77F7
    My rewrite rules print: http://pastebin.com/jbaDANYr

    Would really appreciate anyones help here, I've been tearing my hair out over this all day!

  3. jeroenpanjer
    Posted 4 years ago #

    I was struggling with pagination for hours as well.. This is what I did that worked:

    <?php $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; ?>
    <?php $offset = ( 5 * $paged ) - 5; ?>
    <?php $args=array(‘paged’=>$paged, 'posts_per_page'=>5, 'post_type'=>'YOURPOSTTYPE', 'offset' => $offset); ?>
    <?php query_posts($args); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic