Forums Forums Search & Filter Pro Update total results count after ajax

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

    I’ve been searching thru documentation to find either a jquery method or some other way to update the total # of results counter returned the user when the results are updated via ajax.

    The results count works correctly on initialization b/c it’s using the original PHP $wp_query->found_posts but after the user interacts with the form and filters, I don’t have a way to update the returned results count.

    I’ve been looking thru the docs for hours and can’t find how to do this.

    Ex: 40 results found -> 23 results found

    Trevor
    #100095

    I will ask Ross, the developer, if he knows a method to use, as I do not.

    Ross Moderator
    #100222

    Where are you displaying this count?

    If its inside your ajax container, then it will auto update when the results update.

    If you want to change something dynamically elsewhere on the page, then I would recommend to store the variable in a hidden input, inside your ajax container.

    Then when your results are updated, this hidden input is also updated.

    You can then grab the var with JS and update what you need on your page, you’ll just need to detect when our ajax request has finished so you can grab the new var, which can be found first question:

    https://www.designsandcode.com/wordpress-plugins/search-filter-pro/faqs/

    Hope that helps

    Anonymous
    #100238

    I’ve actually tried using the jquery calls listed in the FAQ and none of them work.

    I have tested to make sure that the actual function they reside in is called (with a console.log) but the actual firing of the sf:ajaxfinish / sf:ajaxstart / sf:init never triggers the console.log output.

    I am trying to display the count outside of the ajax container, but there doesn’t seem to be a way for me to grab the results number once the ajax has run. Placing the the front-end output within the ajax container is fine for the first load, but once the ajax refreshes, it disappears as the plugin is replacing everything within the ajax loading div with the new article content.

    I’m also curious as to how to access the results count var as there doesn’t seem to be documentation about that variable either.

    Ross Moderator
    #100241

    Hi Erik

    Ok so lets roll it back a second.

    1) What display method are you using in the display results tab?

    $query_name->found_posts is the correct way to grab this, but the $query_name may vary depending on your display method / setup

    2) The ajax events – to get this working did you try to wrap them in a function like the last example in the FAQs? Thats usually the issue as you may be hooking into the events too early (when jQuery or S&F has not yet init), try:

    (function ( $ ) {
    	"use strict";
    	
    	$(document).on("sf:ajaxfinish", ".searchandfilter", function(){
    		console.log("S&F ajax finished");
    	});
    
    }(jQuery));

    Let me know how you get on and if you can supply a URL to see where you’ve got to that would really help.

    Best

    Anonymous
    #100244
    This reply has been marked as private.
    Ross Moderator
    #100416
    This reply has been marked as private.
    Anonymous
    #101411

    Hi Ross–

    Any update on this? Turns out I do need to have access to when the ajax events fire / complete, but I can’t get it to work using the code provided.

    Ross Moderator
    #101549
    This reply has been marked as private.
Viewing 9 posts - 1 through 9 (of 9 total)