• Resolved Bea Cabrera

    (@bea-cabrera)


    I’ve visited a number of previous forum entries and didn’t find the solution still. Others have the same problem but their findings weren’t applicable to this case. So I’m hoping someone can give me a hint with this issue. 🙁

    So I have a custom query and already added in the paged argument:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    $snapshotargs=array(
    	'posts_per_page' => 10,
    	'post_type' => 'qd_galleries',
    	'qd_galleries_cat' => 'snapshot',
    	'paged' => $paged
    );
    
    $snapshotposts = new WP_Query( $snapshotargs);

    Then, between closing the loop’s while and if (like states in the codex), I placed the navigation links and reset the query:

    <?php } ?><!-- end while -->
    	<nav id="page_nav">
    		<?php get_previous_posts_link('More »') ?><br/>
    		<?php get_next_posts_link('More »') ?>
    	</nav>
    <?php wp_reset_postdata(); ?>
    <?php }; ?><!-- end if -->

    I even tried with next_posts_link() instead of get_next_posts_link().

    Both of them return blank, empty page_nav div, even though there are almost 150 posts to show and pagination is set to 10.

    What could the problem be? Am I missing something?

    Thank you in advanced for your support!

Viewing 1 replies (of 1 total)
  • Thread Starter Bea Cabrera

    (@bea-cabrera)

    It worked simply by changing the WP_Query method to query_posts(). And obviously getting rid of the reset_postdata function, which would ruin all the links. Be aware of the difference in ‘page’ and ‘paged’ for query_var depending on wether you’re on the blog or not.

    Here’s a stripped down version that works:

    $curpage = (get_query_var('page')) ? get_query_var('page') : 1;
    $snapshotargs=array(
    'posts_per_page' => 10,
    'post_type' => 'qd_galleries',
    'qd_galleries_cat' => 'snapshot',
    'paged' => $curpage
    );
    
    query_posts($snapshotargs);
    $pagecount = $wp_query->max_num_pages;
    
    while(have_posts()):the_post();?>
        <h1><a href='<?php the_permalink();?>'><?php the_title();?></a></h1>
        <p> the_excerpt();?></p>
        <?php endwhile; ?>
    
    /** Note that the pagination is outside of the loop
      <p class='pagination-links'>
       Showing page <?=$curpage;?> of <?=$pagecount;?>&nbsp;&nbsp;
       <?php previous_posts_link();?>&nbsp;&nbsp;<?= ($curpage > 1 && $curpage != $pagecount)?'|':'';?>&nbsp;&nbsp;<?php next_posts_link(); ?>
        </p>

    Cheers!

Viewing 1 replies (of 1 total)
  • The topic ‘Pagination links empty on custom post type query’ is closed to new replies.