Hi Rohan,
Thank you for waiting, while I performed some tests.
I was able to find a way to execute a script only after the last page item has been loaded, using the "wpv-pager-next-page" shortcode.
( ref: https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-pager-next-page )
This shortcode shows the next pages link in the view and in that link, the next page number is in the "wpv_paged" URL parameter.
But when the last page in the view is loaded, this "wpv_paged" URL parameter is not set.
You can first add this shortcode in your view's loop, with a special class "hidden-next-page-link":
[wpv-pager-next-page class="hidden-next-page-link"]Next[/wpv-pager-next-page]
Note: Since we don't actually need this link for navigation through pages, you can use custom CSS code to hide it.
Next, in the view's "JS editor" tab, you can include the updated script, which only refreshes the page, once the last pagination item has been loaded:
( by looking for the "wpv_paged" URL parameter value in the generated next page link )
( function( $ ) {
$( document ).ready( function(){
// execute when pagination completes
$( document ).on( 'js_event_wpv_pagination_completed', function( event, data ) {
// get the href value from the hidden next page link
var pageURL = $("a.hidden-next-page-link").attr("href");
// if that href value doesn't include wpv_paged attribute, it means that this is the last page
if (pageURL.indexOf("wpv_paged=") < 1) {
// reload the page
setTimeout(function () { location.reload(true); }, 5000);
}
});
});
})( jQuery );
I hope this helps and for more personalized assistance around custom code, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
regards,
Waqar