Support » Fixing WordPress » Pagination issues with Custom post queries

  • I have a blog that includes an archive of Custom Posts on the Main Page.

    We got it up and running with pagination of the custom posts working just fine.

    After 9 months the pagination in this part of the site stopped working.

    Below is the code:

    <?php   $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                         $temp = $wp_query;
    			$wp_query = null;
    			$wp_query = new WP_Query(array(
    				'posts_per_page' => 12,
    				'post_type' => 'portfolio',
    				'paged'	=>   $paged
    if ($wp_query->have_posts()) : while ($wp_query->have_posts()) : $wp_query->the_post();
    ///*****the loop****** ///
    <?php endwhile;?>
    <?php if(is_home() && $paged < 2){ ?>
    <div class="nextposts">
    <?php next_posts_link(' See More Posts &raquo;', $wp_query->max_num_pages); ?></div>
    <div class="nextposts" id="upone"><?php next_posts_link(' See More Posts &raquo;', $wp_query->max_num_pages) ?></div>
    <?php } else if(is_home() && $paged > 1){ ?>
    <div class="prevposts"><?php previous_posts_link('&laquo; See Newer Posts') ?></div>
     <div class="nextposts"><?php next_posts_link('See Older Posts &raquo;', $wp_query->max_num_pages) ?></div>
    <?php } ?>
    <?php endif; ?>

    What happens now when you click on the ‘next_posts_link’ you are taken to
    This use to work and now generates a 404 error

    I’ve gone through the extensive support threads in regards to Pagination. and have yet to solve this. To prevent redundancy I will outline in order what I have done so far:

    1. Disabled all plugins
    2. Flush and reset Permalinks in the Permalinks settings menu.
    3. Erase and replace .htaccess file
    4. Tried several variations/reorganizations of the query code
    5. Set my ‘blogs show at most’ to 1 ( lower than my ‘posts_per_page’) in Reading Settings.
    7. Checked that there is no conflicting URL slugs.

    Finally I put a <? print_r($wp_query->query); ?> at the end of my page I’m having trouble with and my 404.php page.

    I found the difference

    paginated page: Array ( [posts_per_page] => 12 [post_type] => portfolio [paged] => 1 )
    Error: Array ( [paged] => 2 )

    I lost the post_type in my query of next_posts_link!!

    How do i maintain [post_type] => portfolio in my 2nd page?

  • The topic ‘Pagination issues with Custom post queries’ is closed to new replies.