Custom Post Type and Pagination
-
Hi
I would like to get some pagination on my page that uses a Custom Post Type. I have tried various plugins and they don’t work.I have managed to find some code that does work but it only allows for 2 pages.
<div class="post-list row text-center"> <?php if ( get_query_var( 'paged' ) ) { $paged = get_query_var( 'paged' ); } else if ( get_query_var( 'page' ) ) { // This will occur if on front page. $paged = get_query_var( 'page' ); } else { $paged = 1; } $my_query = new WP_Query( array( 'post_type' => 'grave', 'posts_per_page' => 10, 'paged' => $paged, 'tax_query' => array( array ( 'taxonomy' => 'gentry', 'field' => 'slug', 'terms' => 'gentries', ) ), ) ); ?> <?php if (have_posts()) { ?> <?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?> <?php get_template_part('template-parts/content', 'grave'); endwhile; } else { ?> <p>Nothing Found</p> <?php get_template_part('template-parts/content', 'none'); ?> <?php } ?> </div> <div class="navigation-c"> <?php printf( '<div>%s</div>', get_next_posts_link( 'Older posts', $my_query->max_num_pages ) ); printf( '<div>%s</div>', get_previous_posts_link( 'Newer posts', $my_query->max_num_pages ) );?>
How can I get pagination to work with more pages please?
Colin
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Custom Post Type and Pagination’ is closed to new replies.