Forums Forums Search & Filter Pro Stop Infinite Scroll If Only One Page or Results

Viewing 9 posts - 1 through 9 (of 9 total)
  • Anonymous
    #122622

    When I only have one page of results if I scroll down the Infinite Scroll feature runs and gives a message say no results found. I don’t want it to run if there is only one page of results. How do I achieve this? Thanks

    Trevor
    #122623

    It should ‘know’ not to do this anyway. Can I see the page in question?

    Anonymous
    #122625

    I can’t show you the page but this is the code

    <?php
    if ( $query->have_posts() ) {
    	echo '<div class="posts-wrapper">';
    
    		while ($query->have_posts())
    		{
    			$query->the_post();
    			get_template_part('templates/content', get_post_type() != 'post' ? get_post_type() : get_post_format());
    		}
    
    	echo '</div>';
    	?>
    	<nav class="pagination" style="display: none;">
    		<ul>
    			<li class="previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></li>
    			<li><span>Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?> (<?php echo $query->found_posts; ?> results)</span></li>
    			<li class="next"><?php previous_posts_link( 'Newer posts' ); ?></li>
    		</ul>
    	</nav>
    	<?php
    } else {
    	echo '<p class="no-results">Sorry, we couldn\'t find any results to match your search. Please try broadening your search, or <a href="' . home_url() . '" title="Return to the homepage">returning to the homepage</a>.</p>';
    }
    ?>
    Trevor
    #122636

    Did you look at the sample code we provide in the templates folder of the plugin?

    Anonymous
    #122644

    OK. I’ve not built our customisation but I can see now from your template that we’re not outputting the right message when there are no results and maybe we need to data attributes as well?

    <div class='search-filter-results-list' data-search-filter-action='infinite-scroll-end'>

    Trevor
    #122647

    It is possible. Keep a copy of what you had, and then try and rebuild. What search display results method are you using?

    Anonymous
    #122652

    Shortcode

    Trevor
    #122658

    Then you should be using that method of coding I showed you, in your results.php file.

    Anonymous
    #122816

    I have restored the default code and message ‘End of results’ and this seems to work OK now. The AJAX still loads and query runs to try and find more results so it isn’t disabled if only one page of results are found from the initial query, but the message makes sense now.

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