Forums › Forums › Search & Filter Pro › Pagination not working properly
Tagged: codex, example, pagination
- This topic has 15 replies, 3 voices, and was last updated 7 years, 4 months ago by Ross.
-
Anonymous(Private) May 9, 2017 at 10:10 pm #107865
Hi Trevor,
Thank you for your time. As requested, I’m posting the issue here, so you can ask Ross to have a look, that would be great.
Basically the issue is that the pagination it’s not working properly.
Here are 2 videos explaining the issue:
https://goo.gl/4aiwFV
https://goo.gl/yYKSmOI’m in process of copying the website to a development server and I can give you admin & ftp access. I’ll reply back once it’s ready.
Anonymous(Private) May 10, 2017 at 6:00 pm #108061Thank you Travor.
I’ve just double checked again. Option number 2 definitely works.
Setting Display results as archive instead of post archive. Although I’m getting the error:
Error: The custom template filesearch.php
cannot be found – go to Display Results tab to fix.But it works. On the main videos page the pagination works, and even after applying a filter, the pagination works.
The only thing which i don’t understand is that Search & Filter plugin doesn’t control the number of post shown on the main page. Is set to 20, but it only shows 10. But once I select a filter, and click submit it goes back to 10.So how is this possible considering search.php cannot be found? weird.
Ross Moderator(Private) May 12, 2017 at 4:37 pm #108542Hi Alex
Ok so I took a look, I see what you mean.
The issue usually is the way pagination works (and how it detects the current page).
S&F uses its own URL var (sf_paged) for pagination, so sometimes this causes issues like this.
I’m not familiar with beaver builder yet, but is there a way to customise pagination, using something like templates in your child theme? If you could figure that out, I know the code changes we would need to make 🙂
—
To explain the issue & solution anyway (it might be useful to beaverbuilder):
Take page 6 of results here – https://yourdevsite/maths-videos/?sf_paged=6
Its clear on your site, the pagination thinks its still on page 1 while S&F has paginated the results to page 6. This is all to do with how your theme (and many others) gets the
current page
variable from WordPress, which is then passed on to the pagination function.A lot themes pagination will look something like:
$current_page = max(1, get_query_var('paged')); echo paginate_links(array( 'base' => get_pagenum_link(1) . '%_%', 'format' => 'page/%#%', 'current' => $current_page, 'total' => $total_pages, ));
Notice, current page is set from this var –
get_query_var('paged')
.To make pagination work correctly in all scenarios, even when the page has been changed dynamically (this could be changed by
pre_get_posts
for example), I personally think its best to get the paged var from the query itself, circumventing the need to know the pagination variable name in the URL or if its been altered dynamically.My solution is to set current page using
$wp_query->query_vars['paged']
– so the code sample above would useglobal $wp_query; $current_page = max(1, $wp_query->query_vars['paged']); echo paginate_links(array( 'base' => get_pagenum_link(1) . '%_%', 'format' => 'page/%#%', 'current' => $current_page, 'total' => $total_pages, ));
This I think is a more compatible approach to handling pagination in general and allows for more options as a developer (and in this case, would allow your theme pagination to work with S&F custom pagination query var).
Anyway, hope that makes sense, if not, figuring out how to customise beaver builder pagination will be all I need to advise next steps 🙂
Best
Ross Moderator(Private) May 13, 2017 at 12:39 pm #108624Hi Alex
I’ve seen that article and tried it out.
It seems those docs are slightly outdated, but may still work for normal templates.
I think it works differently for templates created via the WP admin (in the layouts section I think, where you create the layout for your archive) – this doesn’t seem to be mentioned in the docs / can’t find it.
Thanks
-
AuthorPosts