Support

Account

Home Forums Front-end Issues pagination of dynamically pulled in posts

Helping

pagination of dynamically pulled in posts

  • I have a athlete result page that has various athletes results. When you go to a athlete profile page their results are pulled in. Some athletes have quite a bit of results so I would like to be able to break their results into pages. Right now I have it set to show 5 results and would like a older results and newer results pagination at the bottom of the results. My code is:

    <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 -->

    Please take a look and let me know where I am going wrong. Thank you in advance.

  • Hi @vince_m

    Please take a look at this page to learn more about pagination: https://codex.wordpress.org/Pagination.

    If you have a difficulty with pagination, the best place to ask is in WordPress support forum because it’s not related to ACF anymore. I’m sorry for the inconvenience.

    Thanks 🙂

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.