Support Forums

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Pagination Count is wrong when Filtered

Tagged: 

Viewing 7 posts - 1 through 7 (of 7 total)
  • Lars Faye
    #257006

    Using custom method. Page results are always 55 no matter what category is selected:

    http://labucket.rogerthat.agency/news-stories/

    The pagination is within the ajax target ID/container and before the endif statement. I tested the pagination function without S&F and it paginates correct. I tried with ajax on and off. Rebuilt the cache, as well. What else can I check?

        <?php // Posts Index
        $args  = array( 'search_filter_id' => 314 );
        $articles = new WP_Query( $args ); ?>
    
        <div class="posts-index--content grid">
          <div class="articles" id="articles">
            <?php if ( $articles->have_posts() )  : $is_sticky = false; ?>
              <?php while ( $articles->have_posts() ) : $articles->the_post(); ?>
                <?php include( locate_template('partials/posts/post-entry.php') ); ?>
              <?php endwhile; ?>
    
              <?php if ( $articles->max_num_pages > 1 ) : ?>
                <div class="posts-index--pagination pagination">
                  <?php include( locate_template('partials/posts/post-pagination.php') ); ?>
                </div>
              <?php endif; ?>
    
              <?php else : ?>
                <div class="no-results">
                  <h3>No Results Found</h3>
                </div>
    
              <?php endif; ?>
              <?php wp_reset_postdata(); ?>
    
    Trevor Moderator
    #257017

    Try a test by replacing this line:

    <?php include( locate_template('partials/posts/post-pagination.php') ); ?>

    with this (simple pagination code based on the WordPress Codex):

    <div class="nav-previous"><?php next_posts_link( 'Older posts', $articles->max_num_pages ); ?></div>
    <div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div>
    Lars Faye
    #257025

    Yes, that works fine (I already tested it). But the client wants numerical pagination.

    So, it isn’t that the pagination links don’t work, it’s that it’s always counting 55 pages of results, even after we filter, and those pages that don’t exist lead to a 404 page:

    E.g. this category should only have 5 pages:

    http://labucket.rogerthat.agency/news-stories/?_sft_category=reports

    Lars Faye
    #257027

    Here is the pagination script. I know you can’t debug my code, but wondering if anything pops out at you that would be incompatible with S&F, since this is the pagination function I use for all our sites:

    /* Numerical Pagination
    ========================================================= */
    function post_pagination( $pages = '', $range = 2 ) {
      $showitems = ( $range * 2 ) + 1;
      global $paged;
    
      if ( empty($paged) ) $paged = 1;
      if ( $pages == '' ) {
        global $wp_query;
        $pages = $wp_query->max_num_pages;
        if ( !$pages ) {
          $pages = 1;
        }
      }
    
      if ( 1 != $pages ) {
        if ( $paged > 2 && $paged > $range + 1 && $showitems < $pages ) 
          echo "<a class='first-link' href='" . get_pagenum_link(1) . "' title='Go to First Page'><<</a>";
        if ( $paged > 1 && $showitems < $pages ) 
          echo "<a class='prev-link' href='" . get_pagenum_link($paged - 1) . "' title='Go to Previous Page'><</a>";
    
        for ( $i = 1; $i <= $pages; $i++ ) {
          if ( 1 != $pages && ( !($i >= $paged+$range + 1 || $i <= $paged - $range - 1) || $pages <= $showitems ) ) {
            echo ($paged == $i) ? "<span class='current'>{$i}</span>" : "<a href='" . get_pagenum_link($i) . "' class='inactive' title='Go to Page {$i}'>{$i}</a>";
          }
        }
    
        if ( $paged < $pages && $showitems < $pages ) 
          echo "<a class='next-link' href='" . get_pagenum_link($paged + 1) . "' title='Go to Next Page'>></a>";
        if ( $paged < $pages - 1 &&  $paged + $range - 1 < $pages && $showitems < $pages ) 
          echo "<a class='last-link' href='" . get_pagenum_link($pages) . "' title='Go to Last Page'>>></a>";
      }
    }
    
    Trevor Moderator
    #257036

    If you want numbered pagination, an alternative is to use this free plugin:

    https://wordpress.org/plugins/wp-pagenavi/

    And replace those two lines I gave you with this:

    <?php
    if (function_exists('wp_pagenavi')) {
      wp_pagenavi( array( 'query' => $article ) );
    }
    ?>

    There are also some free addons for WP-PageNavi that give you more styles for it, such as:

    https://wordpress.org/plugins/styles-for-wp-pagenavi-addon/

    Lars Faye
    #257044

    Cool…that worked. Was hoping to avoid a plugin, but, it works and it’s lightweight enough. Thanks!

    Trevor Moderator
    #257049

    Thanks for getting back to me. I will close this thread for now.

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

The topic ‘Pagination Count is wrong when Filtered’ is closed to new replies.