Skip to content

Instantly share code, notes, and snippets.

@machouinard
Created March 10, 2016 09:49
Show Gist options
  • Save machouinard/993c07e82c7bddd55625 to your computer and use it in GitHub Desktop.
Save machouinard/993c07e82c7bddd55625 to your computer and use it in GitHub Desktop.
FacetWP inifinite scroll using button click
(function ( $ ) {
window.fwp_is_paging = false;
$( document ).on( 'facetwp-refresh', function () {
if ( !window.fwp_is_paging ) {
window.fwp_page = 1;
FWP.extras.per_page = 'default';
}
window.fwp_is_paging = false;
} );
$( document ).on( 'facetwp-loaded', function () {
window.fwp_total_rows = FWP.settings.pager.total_rows;
if ( !FWP.loaded ) {
window.fwp_default_per_page = FWP.settings.pager.per_page;
// #more-facet is the "Read More" button on the page
$( '#more-facet' ).on( 'click', function () {
var rows_loaded = (window.fwp_page * window.fwp_default_per_page);
if ( rows_loaded < window.fwp_total_rows ) {
window.fwp_page++;
window.fwp_is_paging = true;
FWP.extras.per_page = (window.fwp_page * window.fwp_default_per_page);
FWP.soft_refresh = true;
FWP.refresh();
$( this ).blur();
}
} );
}
} );
})( jQuery );
@renkcreative
Copy link

Hello,

I create a text link under posts like below and put your code to my custom javascript file.

<a href="#more-facet">Read More</a>

When I click the read more link, there is any change on page. What is my wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment