Forums › Forums › Search & Filter Pro › Normal WP pagination broken if SF is used on the same page
- This topic has 10 replies, 2 voices, and was last updated 7 years, 4 months ago by
Trevor.
-
Anonymous(Private) March 7, 2019 at 11:33 am #204212
So I’m working on a site for a client who wants to have a search form that pops up in an overlay if toggled. Also the results are shown in this overlaying div-element. I’ve configured the search form to use Ajax and Infinite Scroll, everything works just fine.
The problem is that if I’m on a page that has a query that goes like this:
<?php $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $query = new WP_Query(array('cat' => 2, 'posts_per_page' => 20, 'paged' => $paged)); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); get_template_part('templates/news-item', get_post_format()); } if ($query->max_num_pages > 1) { ?> <nav class="prev-next-posts"> <div class="next-posts-link"> <?php echo get_previous_posts_link( '<- Newer' ); ?> </div> <div class="prev-posts-link"> <?php echo get_next_posts_link( 'Older ->', $query->max_num_pages ); ?> </div> </nav> <?php } wp_reset_postdata(); } else {} ?>So it’s paged, as you can see, and it uses the
get_next_posts_linkandget_previous_posts_linkto display the prev/next buttons.Normally these links have urls like site.com/foo/page/2/, but now they are turned into site.com/path/to/searh/page?sf_paged=2. And that of course does not work and it’s not how it should be anyway.
I use shortcode to display the search form and the results in the overlaying element. If I disable the one for the results, the pagination works again. But the search of course does not 🙂
What could cause this behavior? I’ve been mostly developing under Drupal for years, so this might be a simple WP thing I’m missing here…
Trevor(Private) March 7, 2019 at 1:47 pm #204229These links, they are not from the section that has the results, or they ARE from the section (overlay) that has the results?
In our settings in the form, on the Display Results settings tab, if you have Ajax ON, you can set the pagination container. It is normally set to
.pagination aLet us say that the overly is in a div with the class of
overlay, then you might change the pagination selector to.overlay .pagination aAnonymous(Private) March 11, 2019 at 7:12 am #204554Thanks for your reply.
The links are not from the search results (overlay), they are from the other pagination that’s on a page. And that pagination should not use anything from S&F.
I tried your suggestion, but it did not help. So using “infinite scroll” or “normal” as the pagination type makes no difference, no matter how I set the classes for the containers/selectors.
This is the results.php that I’m using (with infinite scroll on):
<?php if ( $query->have_posts() ) { ?> <div class='search-filter-results-list'> <?php while ($query->have_posts()) { $query->the_post(); ?> <div class='search-filter-result-item'> <h2><?php the_title(); ?></h2> <p><?php echo search_excerpt(30); ?></p> </div> <?php } ?> </div> <?php } else { ?> <div class='search-filter-results-list' data-search-filter-action='infinite-scroll-end'></div> <?php } ?>Although I don’t think that’s where the problem is, as I tried the core ones that come with this plugin and the problem still exists.
On the S&F settings page I have set “Infinite Scroll Container” to
.search-overlay .search-filter-results-list. Ajax is on, bookmarking is on..And this is the way the overlay is created on every page:
<div class="search-overlay"> <div class="search-content"> <div class="search-toggle search-toggle-close"> <img src="URL-TO-IMG" width="54" height="34" /> </div> <div class="search-input"> <?php echo do_shortcode('[searchandfilter id="2947"]'); ?> </div> <div class="search-results"> <?php echo do_shortcode('[searchandfilter id="2947" show="results"]'); ?> </div> <?php if ( is_active_sidebar( 'nav_bottom_nineteen' ) ) : ?> <div class="widget-area nav-main-bottom" role="complementary"> <?php dynamic_sidebar( 'nav_bottom_nineteen' ); ?> </div> <?php endif; ?> </div> </div>Anonymous(Private) March 13, 2019 at 9:42 am #204967Ok, to this is what I did:
1. Clean install of WordPress 5.1.1
2. Created a couple of articles to test the paginationNow if I go to the front page that shows the articles and the default pagination for them, it works like it should. So I continue:
3. Installed the newest version of Search & Filter Pro
4. Configured a search form that uses a shortcode, ajax and infinite scroll
5. Put the form and its results to the default theme’s header.php using do_schortcode()Now the default pagination does not work for the article pagination, it just adds
?sf_paged=2to the url. The pagination for the search results work as it should. -
AuthorPosts