Support Forums

There is a new way to get support - via the support tab in your account.

Our support systems are changing, for the better. You'll be able to manage all your support requests from your account, and respond to any tickets via email.

These support forums are now closed - existing tickets will be closed after a month.

Forums Forums Search & Filter Pro double load effect when there is only one page of results

Viewing 10 posts - 1 through 10 (of 10 total)
  • Jonathan Hatch
    #234506

    Hi,

    I’m having trouble preventing the double load effect when there is only one page of results. When there are multiple pages, the span with the data attribute works well. Example: https://abe.stpaulmedia.net/ But when there is only one page, the spinner appears if you scroll. Example: https://abe.stpaulmedia.net/?_sft_focus=civics-citizenship

    The display results method is custom, and I’m using the template engine Twig via the plugin Timber. Here are the relevant bits:

    functions.php

    function spm_modify_blog_homepage_query( $query ) {
    	if ( ! is_admin() && $query->is_home() && $query->is_main_query() ) {
    		$sf_id = get_field( 'sf_id', 'option' );
    
    		$query->set( 'orderby', 'title' );
            	$query->set( 'order', 'asc' );
    		$query->set( 'search_filter_id', $sf_id );
        }
    }
    add_action( 'pre_get_posts', 'spm_modify_blog_homepage_query' );

    index.php

    $context = Timber::context();
    
    $context['catalog_search_form'] = Timber::get_widgets( 'catalog-search-form' );
    $context['posts'] = new Timber\PostQuery();
    $context['pagination'] = Timber::get_pagination();
    
    $templates = array( 'index.twig' );
    
    Timber::render( $templates, $context );

    index.twig

    <div class="ajax-container">
    	<div class="is-container">
    		{% if posts %}
    			{% for post in posts %}
    				{% include 'blocks/preview.twig' %}
    			{% endfor %}
    		{% endif %}
    
    		{% if pagination.current == pagination.total %}
    			<p data-search-filter-action="infinite-scroll-end">End of results</p>
    		{% endif %}	
    	</div>
    </div>

    I tried searching the forums but didn’t find this specific issue. Thanks for taking a look, and let me know if you need more info.

    Trevor Moderator
    #234553
    This reply has been marked as private.
    Jonathan Hatch
    #234628
    This reply has been marked as private.
    Jonathan Hatch
    #235001
    This reply has been marked as private.
    Ross Moderator
    #235131
    This reply has been marked as private.
    Ross Moderator
    #235238

    Hi Jonathan

    So I found a solution to this.

    S&F was ignoring data-search-filter-action='infinite-scroll-end' on page load, and only looking for it AFTER fetching more results via Ajax.

    I have updated our plugin to fix this.

    All you need to do is add the attribute to your results somewhere, when you know the current set of results are in fact the total set of results, for my testing, I modified our infinite scroll template by doing this:

    Found <?php echo $query->found_posts; ?> Results<br />
    <?php
    	//prevent double load effect if the first set of results are the total results
    	$page = intval($query->query_vars['paged']);
    	$infinite_scroll_end_markup =  '';
    	if($page==1){
    		if(intval($query->found_posts) <= intval($query->query_vars['posts_per_page'])){
    			//then all the results loaded in the first page
    			$infinite_scroll_end_markup = " data-search-filter-action='infinite-scroll-end'";
    		}
    	}
    ?>
    <div class='search-filter-results-list' <?php echo $infinite_scroll_end_markup; ?>>
    

    I hope that helps 🙂

    Jonathan Hatch
    #235364
    This reply has been marked as private.
    Ross Moderator
    #235408

    Hi Jonathan

    Just to confirm that all worked ok and I can close this thread?

    Thanks

    Timo Hubois
    #276453

    What was the solution to get it working? Currently I use Timber and have some problems to get the filtered results.

    Trevor Moderator
    #276455

    I have made the one post was was important visible for you.

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

You must be logged in to reply to this topic.