pagination with dynamically pulled in posts
-
I have a athlete profile page that pulls in that athletes results. I would like to limit the results to only 5 per page and then have pagination to go to older results. I have pagination that works on pages but will not work for this. Please take a look at the code below and let me know where I am going wrong.
<section class="col-sm-12"> <?php $athlete = single_post_title('', false); $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $args = array( 'post_type' => 'result', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => 5, 'paged' => $paged, 'meta_query' => array( array( 'key' => 'result-athlete', // athlete results name 'value' => $athlete, // athlete name 'compare' => '=' ), ), ); $the_query = new WP_Query( $args ); ?> <div class="col-md-12 index-results-Section"> <h3>Results </h3> <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <div class="index-resultsSingle"> <div class="col-md-2 index-resultsAthlete"> <?php the_field( 'result-athlete' ); ?> </div><!-- .index-resultsAthlete --> <div class="col-md-7 index-resultsSport"> <?php the_field( 'result-sport' ); ?> <?php the_field( 'result-date' ); ?> </div> <!-- .index-resultsSport --> <div class="col-md-3 index-resultsResult"> <?php the_field( 'result-result' ); ?> </div> <!-- .index-resultsResult --> <div class="clearfix"></div> </div> <?php endwhile; else: ?> <h4>There are no results for this athlete at this time.</h4> <?php endif; ?> <div class="row"> <!-- Next and Previous --> <?php if ($the_query->max_num_pages > 1) { // check if the max number of pages is greater than 1 ?> <nav class="prev-next-posts"> <div class="col-md-4 prev-posts-link"> <?php echo next_posts_link( '< Older Press Releases', $the_query->max_num_pages ); // display older posts link ?> </div> <div class="col-md-4 col-md-offset-4 next-posts-link"> <?php echo previous_posts_link( 'Newer Press Releases >' ); // display newer posts link ?> </div> </nav> <?php } ?> </div> <div class="clearfix visible-sm"></div> </div> </section><!-- .col-sm-12 -->
Any help would be greatly appreciated. Thank you in advance.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘pagination with dynamically pulled in posts’ is closed to new replies.