Pagination does not work with custom query
-
Hello, please forgive me but I’m new to WordPress and Seriously Simple Podcasts.
I have a custom query that loads my podcast episodes first page, but second page cannot be found.
Can someone please explain to me what is wrong with my code?
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'post_type' => array('podcast'), 'posts_per_page' => 9, 'paged' => $paged, ); $query = new WP_Query( $args ); if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); get_template_part( 'template-parts/post'); endwhile; ?> <div class="w-full text-center"> <?php if ($query->max_num_pages > 1) { // check if the max number of pages is greater than 1 ?> <nav class="prev-next-posts"> <div class="prev-posts-link"> <?php echo get_next_posts_link( 'Older Entries', $query->max_num_pages ); // display older posts link ?> </div> <div class="next-posts-link"> <?php echo get_previous_posts_link( 'Newer Entries' ); // display newer posts link ?> </div> </nav> <?php } ?> </div> <?php else : get_template_part( 'template-parts/content', 'none' ); endif; ?>Thank you in advance for your help, looking forward to figuring this out.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Pagination does not work with custom query’ is closed to new replies.