Forums › Forums › Search & Filter Pro › Pagination Count is wrong when Filtered
Tagged: pagination
- This topic has 6 replies, 2 voices, and was last updated 4 years, 4 months ago by Trevor.
-
Anonymous(Private) August 21, 2020 at 8:57 pm #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(Private) August 22, 2020 at 8:09 am #257017Try 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>
Anonymous(Private) August 22, 2020 at 10:33 pm #257025Yes, 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
Anonymous(Private) August 22, 2020 at 10:35 pm #257027Here 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(Private) August 23, 2020 at 7:45 am #257036If 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:
-
AuthorPosts